Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Synchronize a new Active Directory domain with an existing Office 365 tenant
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 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