Solved

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

Posted on 2014-12-11
5
171 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 84

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 84

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doing AD cleanup with Powershell 9 55
Permission on folders 6 20
ADFS:  Step by Step to enable MFA with ADFS 16 29
How do audio drivers work? 4 43
Set OWA language and time zone in Exchange for individuals, all users or per database.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 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