Solved

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

Posted on 2014-11-05
21
85 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Utilizing an array to gracefully append to a list of EmailAddresses
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

19 Experts available now in Live!

Get 1:1 Help Now