Solved

Importing lines from a text file if they start with 123-abcd in powershell array

Posted on 2014-12-11
5
167 Views
Last Modified: 2016-11-23
Hello.

Im trying to import lines from a text file into an array.
The only I know for sure that is that all lines always start with a combination of 3 numbers and 4 letters:

350-11079 Chassis with up to 10 Hard Drives and 3 PCIe Slots, Low Profile PCI Cards Only 2 SR
350-10048 No Bezel Option - Rack Chassis 2 SR
370-AAGI 16GB RDIMM, 1600MHz, Low Volt, Dual Rank, x4 16 SR
370-22141 1600 MHz RDIMMs 2 SR
370-22145 Performance Optimized 2 SR
374-14451 Heat Sink for PowerEdge R620 4 SR
374-14454 DIMM Blanks for Systems with 2 Processors 2 SR

How can I get all those lines into an array or directly in a csv
The text source is an PDF to text converted dell invoice so there is a lot of extra text which I don't need...

Thanks!
0
Comment
Question by:Hans de Jongh
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40494247
Sorry, you're not quite clear; do you want all lines starting "with a combination of 3 numbers and 4 letters" (of which there is only one in the sample), or do you want "all those lines" as in the sample?
This will get only lines starting with 3 numbers and 4 letters:
Select-String -Path .\test.txt -Pattern '^\s*\d{3}-[a-z]{4}\s+?.*$'

Open in new window

This will get all lines starting with 3 numbers and any 4- or 5 charcater long combination of letters and numbers:
Select-String -Path .\test.txt -Pattern '^\s*\d{3}-[a-z0-9]{4,5}\s+?.*$'

Open in new window

0
 

Author Comment

by:Hans de Jongh
ID: 40494253
sorry, you'r right.
I want all lines with every possible combination.
Ill test it out later on!
Thanks
0
 

Author Comment

by:Hans de Jongh
ID: 40494584
sorry I just noticed that dell ran out of partnumbers so they decided to use this aswell:

123-12345

is it possible to do that in one select-string?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 40494594
That should be found with the above expression as well. What exactly is the problem?
0
 

Author Comment

by:Hans de Jongh
ID: 40494602
oh you are so right! thanks a lot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now