0

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
RINGFIEL 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!

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.