开发者

Help with Script for Extracting Specific Data from String

开发者 https://www.devze.com 2023-01-13 03:45 出处:网络
Below is a list of data in a single file. I\'d like to run this in Powershell. LESCAR8507/31/101700678991

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:

  1. splits each line at the ' / '
  2. Takes the second part of the split (what you are interested in), and splits again at whitespace.
  3. The resulting elements are then joined together using a comma.
0

精彩评论

暂无评论...
验证码 换一张
取 消