The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 9 12-04-2008 04:04 PM
Pivot variable record length file and change delimiter thomasr Shell Programming and Scripting 3 10-08-2007 08:40 PM
fixed record length george_ Shell Programming and Scripting 16 03-28-2006 05:41 AM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 01:09 PM
Parsing data and retaining the full length of variable app4dxh Shell Programming and Scripting 3 11-22-2002 12:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 09-28-2004
Barb Barb is offline
Registered User
  
 

Join Date: Sep 2004
Location: Florida
Posts: 24
Question Parsing a variable length record

I need to pick a field out of a variable record - the field is always found 4 fields after a certain text string, but it can be on any line of the record and in any position across the record on a line. I have had no luck through any of the Unix editors being able to cut a field that isn't always at the same spot in a record. Does anyone have any ideas - or do you know how I can replace a character string in a file with a hard return?
  #2 (permalink)  
Old 09-28-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
This sounds either very hard or downright impossible. We need a lot more info. Is the data file a collection of lines, each ending with a new line character? How do you tell where a field ends? How do you tell where where a record ends? How about some sample data?
  #3 (permalink)  
Old 09-28-2004
Barb Barb is offline
Registered User
  
 

Join Date: Sep 2004
Location: Florida
Posts: 24
Here is a sample of the file - the '~ST' appears at the end of every record. What I need to pull out is the 5th field from the ~ST (fields are seperated by '^') based on the value of 855 or 856 in the 1st field. I know how to use awk to search for a character string and return values in fields on the line. But I have never had to start any of the editors with lines over multiple rows and fields all over the place. And a record can be any length. I feel like I've entered the twilight zone. Thanks for any help you can give me on this.
  #4 (permalink)  
Old 09-28-2004
Barb Barb is offline
Registered User
  
 

Join Date: Sep 2004
Location: Florida
Posts: 24
Here is the actual sample - whoops
Code:
   ~REF^BO^C61102^BIN LOCATION~PO1^29^6.00^PK^9.50^^VC^435916^IN^916~PID^F^^^^PAD, DRI FLOW (12/PK 6PK/CS)~ACK^AC^6.00^PK~REF^
AP^C400=PK   ^          ~REF^BO^C61102^BIN LOCATION~CTT^29^334.00~SE^139^0001~GE^1^5644~IEA^1^000005701~@@@@@@@@@@@@@@@@@@@@@@@@
ISA^00^D011-56018^00^VAX-VMSSYS^01^GENERAL MEDICAL^ZZ^011            ^040506^1702^U^00200^000005702^0^P^|~GS^PR^GM^56018^040506^
1702^5645^X^003020~ST^855^0001~BAK^06^AC^440597^040506^^^^^040506~REF^IV^723065~DTM^055^040506^1703~PER^BD^JANET ARROYO~N1^ST^^9
1^573~N1^BT^0100^91^56018~PO1^1^12.00^BX^7.39^^VC^213458^IN^15074~PID^F^^^^ELECTRODE, EKG INSTATRACE 5'S (50/BX)~ACK^AC^12.00^BX
~REF^AP^C72=BX    ^          ~REF^BO^C61802^BIN LOCATION~CTT^1^12.00~SE^14^0001~ST^855^0002~BAK^06^AC^440598^040506^^^^^040506~R
EF^IV^723066~DTM^055^040506^1703~PER^BD^SAE JACKSON~N1^ST^^91^657~N1^BT^0100^91^56018~PO1^1^12.00^EA^0.28^^VC^278487^IN^1207~PID
^F^^^^BATTERY, ALKALINE "AAA" (24/BX 3BX/CS)~ACK^AC^12.00^EA~REF^AP^C60=BX    ^          ~REF^BO^C61202^BIN LOCATION~PO1^2^24.00
^EA^0.47^^VC^278484^IN^127~PID^F^^^^BATTERY, ALKAL "C" (SPEC) (12/BX 6BX/CS)~ACK^AC^24.00^EA~REF^AP^C100=BX   ^          ~REF^BO
^C61802^BIN LOCATION~PO1^3^48.00^EA^0.25^^VC^278485^IN^130~PID^F^^^^BATTERY, ALKAL "AA" (24/BX 6BX/CS)~ACK^AC^48.00^EA~REF^AP^C3
02=BX   ^          ~REF^BO^C61902^BIN LOCATION~PO1^4^6.00^EA^0.58^^VC^186661^IN^780~PID^F^^^^SOD CHL, IVSOL 0.9% 500ML (24/CS)~A
CK^AC^6.00^EA~REF^AP^C305=CS   ^          ~REF^BO^C61102^BIN LOCATION~CTT^4^90.00~SE^29^0002~GE^2^5645~IEA^1^000005702~@@@@@@@@@
ISA^00^D011-56018^00^VAX-VMSSYS^01^GENERAL MEDICAL^ZZ^011            ^040506^1801^U^00200^000005703^0^P^|~GS^PR^GM^56018^040506^
1801^5646^X^003020~ST^855^0001~BAK^06^AC^440601^040506^^^^^040506~REF^IV^723079~DTM^055^040506^1803~PER^BD^SCOTT FITZGERALD~N1^S
T^^91^609~N1^BT^0100^91^56018~PO1^1^15.00^EA^6.08^^VC^405660^IN^14789~PID^F^^^^C

Last edited by Perderabo; 09-29-2004 at 12:00 PM..
  #5 (permalink)  
Old 09-28-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Whatta mess...

Maybe this will get it...

sed -n '/\~ST\^/s/.*\~ST\^//p' < inputfile | awk -v FS=^ '$1=855 { print $5 }'
  #6 (permalink)  
Old 09-28-2004
Barb Barb is offline
Registered User
  
 

Join Date: Sep 2004
Location: Florida
Posts: 24
Perderabo, you are wonderful - Thank you very much it worked perfectly.
  #7 (permalink)  
Old 09-28-2004
rhfrommn rhfrommn is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2003
Location: Minnesota
Posts: 422
Wow.

That was pretty amazing Perderabo, being able to figure out how to extract the data from that mess - and getting it right on the first try.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0