Solved

How can I change this Powershell script so as to list all the identifiers?

Posted on 2014-11-05
21
88 Views
Last Modified: 2014-11-28
Script:

Output desired:

Company:              CompanyCode        
Type:                       810
Identifier:               000000001
Identifier:               000000002
Identifier:               000000003
Control Number:  123456789


I need the scrip to list any identifiers it finds with each data set starting with ISA and ending in IEA which are found within the file.
0
Comment
Question by:100questions
  • 8
  • 6
  • 2
  • +3
21 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40424929
Please supply a sample text file for input and document its output.
0
 

Author Comment

by:100questions
ID: 40424996
Sample Input data:
ISA*00*          *00*          *12*1234567891     *ZZ*COMPANYCOL     *213456*1234*A*00123*123000010*1*P*>~
GS*IN*2134567891*1234567891*20141024*1234*00*X*001234~
ST*810*123456789~
BIG*20141020*123456.*20140917*1234567.~
N1*RI*COMPANY*0*000000000~
N1*BT*COMPANY 2*0*12345678910000~
ITD*00*2*****00~
DTM*000*20141020~
FOB*CC~
IT1*1*200*CA*5.4**UN*123456789123*VN*01234A~
IT1*2*50*CA*1.4**UN*213456789122*VN*02345A~
IT1*3*60*CA*12.4**UN*789456123123*VN*06789A~
TDS*1234567~
ISS*1234*CA*12345*LB~
SE*12*123456789~
ST*810*98763254~
BIG*20141020*123456.*20140917*1234567.~
N1*RI*COMPANY*0*000000000~
N1*BT*COMPANY 2*0*12345678910000~
ITD*00*2*****00~
DTM*000*20141020~
FOB*CC~
IT1*1*10*CA*1.4**UN*783456789123*VN*01235A~
IT1*2*2*CA*2.4**UN*789456789122*VN*02346A~
IT1*3*30*CA*1.5**UN*239456123123*VN*06788A~
TDS*1234567~
ISS*1234*CA*12345*LB~
SE*12*98763254~
GE*1*10~
IEA*1*123000010~

Open in new window

0
 
LVL 18

Expert Comment

by:x-men
ID: 40466384
$(gc c:\temp\my.imput.txt).split("*")
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 3

Expert Comment

by:Barry Molenwijk
ID: 40466389
Which parts of the input would you like included in the output? Could you highlight those or create the exact output you want based on this input so we can reverse-engineer it?
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 40466604
You rather missed out the:

> document its output

This question cannot be answered without some kind of documentation to allow us to figure out which bits of the snippet represent the fields you've requested.

Chris
0
 

Author Comment

by:100questions
ID: 40469497
I've requested that this question be deleted for the following reason:

Not enough information was provided for the experts, deleting this.
0
 
LVL 10

Expert Comment

by:JoeKlimis
ID: 40469296
Hi would you like me to  answer this question , i will create you a script
0
 

Author Comment

by:100questions
ID: 40469453
Sure Joe, if you have enough info to go by, then yes if possible.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40469494
We would all like to answer the question but first you have to do as we asked and provide DETAILS of input AND outputs, rules of how to get from input to output.
What you have given us so far allows only guessing.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40469498
Is deleting a question because you didnt provide enough information and wont provide it, a good cause for deletion and points refund?
0
 

Author Comment

by:100questions
ID: 40469656
Post to everyone who wrote in..   I've posted an Output example, and I've posted the Data Input example.   If this is not enough information for anyone, and since none of the experts have provided a solution, and I've requested for this to be closed - if no one can work with what I have, then we can safely delete the question...
0
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40470161
Hi

Please Try the following and let me know how you get on

 
$dataFile		= "data3.txt"
$resultsFile	= "Output.txt"
out-file $resultsFile  -encoding ascii
$data 		 	= get-content $dataFile
$result			= ""
write-output "Processing $($data.count) lines of data"
$count  = 0

$count=0
$lines=@()
$allident = @()
foreach ($line in $data)
{
$lines+=$line
	$SplitLine =$line.split("*")
	switch ( $splitLine[0] )
	{
	"N1" 	{
			$company = $splitline[1]
			$type=""
			$Ident=""
			$controlnumber=""
			
			}

	"ST" 	{ 	$count++
				$doctype  =  $splitline[1]}
	"SE" 	{ 	
				$controlNumber  =  $splitline[2].split("~")[0]}
	
	"IT1" 	{   
				$ident = $SplitLine[9].split("~")[0]
				$allident += $ident
				}
	"IEA"	{
				"Company:  $company"|out-file $resultsFile -append -encoding ASCII
				"Type:     $doctype"| out-file $resultsFile -append -encoding ASCII
				foreach ($idents in $allident ) {"Identifier: $idents"| out-file $resultsFile -append -encoding ASCII}
				"Control Number: $controlnumber"| out-file $resultsFile -append -encoding ASCII
				"" | out-file $resultsFile -append -encoding ASCII
				$allident = @()
			}
	}
}

Open in new window

0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40470504
@100questions
It is customary when asking for help, in any walk of life, to be courteous and responsive. When you are asked for an explanation or further details, a response of  "I've posted an Output example, and I've posted the Data Input example.   If this is not enough information for anyone, and since none of the experts have provided a solution, and I've requested for this to be closed - if no one can work with what I have, then we can safely delete the question"  is hardly professional or conducive to eliciting a good response.

You question gave two bits of data with no explanation and nod no details of how it was structured.  As I stated earlier, we could have Guessed and wasted everyone's time, instead I asked for a quick explanation.

Alas you either don't know what you want or how to articulate it and would rather alienate the experts with your responses.
0
 

Author Comment

by:100questions
ID: 40470569
@Neilsr - Good day.  Thanks for your response.  I do not wish to come across as unprofessional.  In the future, I will try to provide more information.  Regards.   100questions.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40470577
Just another note. Your question is titled...

How can I change this Powershell script so as to list all the identifiers?

You did not however provide ANY powershell script or snippets for us to change!
0
 

Author Comment

by:100questions
ID: 40470583
Hi Neil.  Yes, you are correct, this was my omission, I should either have included the script or changed the title.  My apologies.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40470601
So you have a script already??  Had you uploaded that too, you would probably had an answer in the first hour....
0
 

Author Comment

by:100questions
ID: 40470602
Hi Neil.  I don't have a script handy at this time.  I will try Joe's script to see how it works.
0
 

Author Closing Comment

by:100questions
ID: 40470610
Thanks Joe for working on this, much appreciated.

This was the output from your script:

Company:  BT
Type:     810
Identifier: 01234A
Identifier: 02345A
Identifier: 06789A
Identifier: 01235A
Identifier: 02346A
Identifier: 06788A
Control Number: 98763254
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

8 Experts available now in Live!

Get 1:1 Help Now