# Search and Replace CRLF

**URL:** <https://forums.powershell.org/t/search-and-replace-crlf/2417>\
**Category:** PowerShell Help\
**Created:** [April 3, 2014, 2:41am UTC](https://forums.powershell.org/t/search-and-replace-crlf/2417 "2014-04-03T02:41:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick-metcalfe](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@patrick-metcalfe](https://forums.powershell.org/u/patrick-metcalfe)\
**Post date:** [April 3, 2014, 2:41am UTC](https://forums.powershell.org/t/search-and-replace-crlf/2417/1 "2014-04-03T02:41:15Z")

</div>

Trying to replace **CRLF** in a small PowerShell script

Works OK with standard characters bit not with `n ;

file.txt look like this:

Line1  
Line2  
Line3  
Line4

would like the file to look like this:

Line1,Line2,Line3,Line4

Here is the script below

$Strings = Get-Content e:\powershell\file.txt

Foreach ($String in $Strings){

```
$string -replace ("`n" , ",")

```

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 3, 2014, 2:43am UTC](https://forums.powershell.org/t/search-and-replace-crlf/2417/2 "2014-04-03T02:43:49Z")

</div>

Get-Content returns an array of strings, by default, and those strings will not include the actual CR/LF characters that were present in the file. All you need to do is use the -join operator to combine the array back into a single comma-separated string:

```
$String = (Get-Content e:\powershell\file.txt) -join ','
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/search-and-replace-crlf/2417/3 "2024-05-16T20:52:13Z")

</div>


