Below is a list of data in a single file. I'd like to run this in Powershell.
LESCAR85 07/31/10 1700678991 / 70039536 $35.00
SQUADCT8 07/31/10 1698125739 / 70039539 $35.00 RI开发者_运维问答NGFIEL 07/29/10 11041563 / 70039639 $35.00
The 8 digit number and then the dollar amount at the end I would like convert to csv so that I can use that in an excel file. The first set of longer numbers is not always the same which changes the number of spaces between the 8 digit sequence I need and the dollar amount.
Thanks!
As long as ' / ' (slash bounded by spaces) always seperates the data you are interested in from the beginning of the string, then you can use this:
get-content yourDataFile.txt | foreach{(-split ($_ -split ' / ')[1] ) -join ','} > yourResult.csv
What the foreach loop does:
- splits each line at the ' / '
- Takes the second part of the split (what you are interested in), and splits again at whitespace.
- The resulting elements are then joined together using a comma.
精彩评论