I have some TXT files that have two rows with content I want to match and Add to another file:
I'm using this command:
Select-String -path '.*.txt' -Pattern '((?<=Pattern1 ).*|(?<=Pattern2: ).*)' -AllMatches| ForEach-Object{$_.Matches.Value} | Add-Content C:List.xls
It works, but on the output List.xls, the two expected matches from each of the input txts are put in two rows, like this:
Match1
Match2
So, when I try to open (import) my List.xls on Libreoffice Calc, it won't let me put Match1 and Match2 in different columns. It forces two rows.
Is there a way I can change the Select-String code to make the matches come out like this:
Match1,Match2
This way, when I open (import) the List.xls file, Openoffice Calc willl be able to separate Match1 and Match2 in two columns.
Thanks a lot.
question from:
https://stackoverflow.com/questions/65872191/multiple-regex-matches-in-powershell-output-with-add-content-in-the-same-line 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…