Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-12-11
5
Medium Priority
?
186 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

722 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