Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

saperated comma and no new line after regular expression

$
0
0

Hi developer,

i am trying to read in text file. The file name is test.txt:

aa aa aa 4
bb bb bb 3
cc cc cc 5
dd dd dd 1
ee ee ee 2

Here is my sample windows powershell script:

$reg = ".........."
Get-Content .\Test.txt|Select-String -Pattern  $reg -AllMatches | ForEach-Object { $_.Matches } |
ForEach-Object { $_.Groups[0].value}

output:
aa
aa
aa
4
bb
bb
bb
3
cc
cc
cc
5
dd
dd
dd
1
ee
ee
ee
2

I want to display output like this:
aa,aa,aa,4
bb,bb,bb,3
cc,cc,cc,5
dd,dd,dd,1
ee,ee,ee,2

How to saperated comma and no new line after regular expression?

Thanks



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>