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

x
?
Solved

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

Posted on 2014-11-05
21
Medium Priority
?
93 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 71

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 11

Expert Comment

by:Joe Klimis
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 11

Accepted Solution

by:
Joe Klimis earned 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

660 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