Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:09:57+00:00 2026-06-02T05:09:57+00:00

Assume the simple file substitution below: get-content db.cfg | %{$_ -replace ‘a’, ‘b’} |

  • 0

Assume the simple file substitution below:

get-content db.cfg | %{$_ -replace 'a', 'b'} | out-file db.cfg.new -encoding default

out-file automatically uses \r\n as a line separator. Is there a way to force a different separator (like \n)?

I’m looking for an elegant solution. Other than that, one can certainly build the whole file as a string in memory and then write it out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:09:59+00:00Added an answer on June 2, 2026 at 5:09 am

    You could use StreamWriter instead of the Out-File cmdlet like this:

    $writer = [system.io.file]::CreateText("\path\to\db.cfg.new")
    $writer.NewLine = "`n"
    get-content db.cfg | %{$_ -replace 'a', 'b'} | % { $writer.WriteLine($_)}
    $writer.Close()
    

    It’s not quite as slick as a one-liner, but at least it’s easy to read and you’re still streaming the file one line at a time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume I have a simple XML file: <data> <text>Hello world!&lt;br&gt;Nice to see you
I'm trying out log4j in a simple test app. I create a new Java
Lets assume a simple Spring MVC Controller that receives the ID of a domain
Let's assume we have a simple internet socket, and it's going to send 10
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
I need to write a simple script to replace a block of text in
From the should be simple, but... files: Trying to get started with jQuery UI.
Consider this simple fabric file: def wrapper(): f1() f2() @hosts([host1]) def f1(): run('ls') @hosts([host2])
We have an XML file with a very simple implementation of XLink : <root
Given a simple code like : $file = 'hugefile.jpg'; $bckp_file = 'hugeimage-backup.jpg'; // here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.