Solved

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

Posted on 2014-12-11
5
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 85

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 85

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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ā€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 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