The UNIX and Linux Forums  

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
How to strip non numerical data out of file? Juha Shell Programming and Scripting 10 01-09-2007 03:09 AM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 06:25 AM
How to strip the contants from a file isingh786 UNIX for Dummies Questions & Answers 2 12-16-2005 03:11 PM
How to strip apostrophe from a file aquimby Shell Programming and Scripting 8 06-23-2005 12:04 PM
trying to strip the first 4 char. of a file out via commandline Optimus_P UNIX for Dummies Questions & Answers 2 06-12-2001 10:02 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 75
how to strip out the contents of file using grep

Hi,

I am receving a file from remote site which has EDI information for 830, 862 and 997 and I want to extect the data for 997 using grep's or any other methods.

The data look like this:

ISA~000
0000-0001-1000~997
AK1000~m
000~IEA~M

ISA~000
0000-0001-1000~849
000~IEA~M

ISA~000
0000-0001-1000~862
000~IEA~M

What I want to do is just extract the portion starting from ISA containing 997 upto the next line where it has "000~IEA~M" i.e. where it ends and not the info for 849 and 862 and redirect the output to some file. I am sure there must be some easy way to do it. In the file there are no spaces between data. I am just adding the spaces to make it more readable.

TIA,
Inder
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-22-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
nawk -f is.awk myFile.txt

is.awk:
Code:
BEGIN {
  FS=RS=""
  PAT="~997$"
}
{
  for(i=1; i <= NF; i++)
    if ( match( $i, PAT )) {
      print
      next
    }
}
Reply With Quote
  #3 (permalink)  
Old 11-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 75
Hi vergse99,

Thanks for the reply!!!

When I am trying to run the script. I am getting this error message:

I checked for nawk and we hdon't have that installed.

dilbert:/UTIL/EDI/DATA/inbound/recent/inder>awk -f is.awk ame29454.0511190545
awk: Input line ISA~00~ ~00 cannot be longer than 3,000 bytes.
The source line number is 3.
Reply With Quote
  #4 (permalink)  
Old 11-22-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
do you have 'gawk'?
Reply With Quote
  #5 (permalink)  
Old 11-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 75
yes, I do have gawk. I tried running it with using gawk but that did not work. I think it's my fault. I did not explain to you data correctly.
That's how the data looks like:

ISA~00~ ~00~ ~
ZZ~F159B ~ZZ~U1CAD ~050110~1946~U~00200~000010378~0~P~<GS~
FA~TC12A~U1CAD~050110~1938~000010378~X~002002ST~997~0001AK1~SH~1078A
K2~856~10780001AK5~AAK9~A~1~1~1SE~6~0001GE~1~000010378
IEA~00001~000010378ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD
~050110~2236~U~00200~000010379~0~P~<GS~SS~0095A~U1CAD~050110~2231~0000
10379~X~002002FORDST~862~0001BSS~05~050080000369~050110~SH~050110~050124
~000-24~~~~CN1~ST~~92~0095AN1~SF~~92~U1CADN1~IC~~92~DPVXBLIN~~BP
~5S4P 7F293 AAUNT~PCREF~DK~2FFST~144~C~D~050110FST~144~C~D~05011
1FST~144~C~D~050112FST~144~C~D~050113FST~144~C~D~050114FST~144~C
~D~050115FST~144~C~D~050116FST~144~C~D~050117FST~144~C~D~050118F
ST~144~C~D~050119FST~144~C~D~050120FST~144~C~D~050121FST~144~C~D~050
122FST~144~C~D~050123FST~144~C~D~050124CTT~1~2160SE~25~0001G
E~1~000010379IEA~00001~000010379

There is no separation between the data ot atleast it does not look like. It starts with "ISA" and then has either 997 or 862 in the data and then it has IEA at about the end and some text after that and again starts with ISA.

I know, I am trying to say so many things at the same time. Please let me know if I can explain in a better way or send it to you directly.

Regards,
Inder
Reply With Quote
  #6 (permalink)  
Old 11-22-2005
Registered User
 

Join Date: Jul 2005
Location: Chicago, IL
Posts: 93
Do you have perl? If so, what version? (do: /path/to/perl -v ).

/path/to may be /usr/bin or /usr/local/bin
-Mike
Reply With Quote
  #7 (permalink)  
Old 11-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 75
Yes, I do have perl and her is the version of the perl:

perl -v

This is perl, version 5.005_03 built for PA-RISC2.0
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0