how to strip out the contents of file using grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to strip out the contents of file using grep
# 1  
Old 11-22-2005
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
# 2  
Old 11-22-2005
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
    }
}

# 3  
Old 11-22-2005
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.
# 4  
Old 11-22-2005
do you have 'gawk'?
# 5  
Old 11-22-2005
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
# 6  
Old 11-22-2005
Do you have perl? If so, what version? (do: /path/to/perl -v ).

/path/to may be /usr/bin or /usr/local/bin
-Mike
# 7  
Old 11-22-2005
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem to grep contents from a file

hi, I'm trying to grep content from one file in another file. The file that I'm searching into is large and hence I need to temporarily unzip it first. gzip -dc ALL.chr2.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz | grep '169997024\|190670539\|128051369' >... (2 Replies)
Discussion started by: janshamsani
2 Replies

2. Shell Programming and Scripting

Grep the contents of a file with another file

hey guys, i got a easy one - i think. i got 2 files: file a.txt: 111 222 333 file b.txt: dave the killer TXTFF FGGD 222 herry FDSFG FDSFG 22 susan RHRHER 466 google FEEFF 686 heads night (2 Replies)
Discussion started by: boaz733
2 Replies

3. Shell Programming and Scripting

need to grep contents of a file within specific time span. regex i am using is not working

Hi , I am trying to extract contents of a file between specified time stamp. but it does not seem to work. i am trying to extract output of /var/adm/messages between 15:00:00 to 15:23:59 . i have tried two regex the first one seems to kind of work. it displays some output. the second one is... (13 Replies)
Discussion started by: chidori
13 Replies

4. Shell Programming and Scripting

Grep -v contents of a list file from another file.

Hello, I am trying to get output from FILE2 that excludes servers from list FILE1. I've tried a for loop with no success. Any ideas how to go about this? FILE1 contains: server1 server2 server3 server4 server5 FILE2 contains: server1:ERROR:user1: error message... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

5. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

6. Shell Programming and Scripting

Grep a pattern given in one file at other file and display its corresponding contents as output.

***************************************** Right now i have this current system. I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which... (7 Replies)
Discussion started by: abinash
7 Replies

7. Shell Programming and Scripting

How to grep the contents inside a tar file

Hi All I have searched the possibility of this options everywhere but am unable to find it in any forum. I have a tar file inside which there are n number of files and i dont know them. I need to grep a word inside the tar file and need to know in which file the word resides. > cat a... (2 Replies)
Discussion started by: Whiteboard
2 Replies

8. Shell Programming and Scripting

find file and print only contents with a hit by grep

Hi, can someone help me. I have some files and search a content in this files. If i have a hit I will print a output: filename:content But are more hits in one file: The output is always filename:content E.G. Seach about "three" file1 {one, two, three, four, three} file2... (5 Replies)
Discussion started by: Timmää
5 Replies

9. Shell Programming and Scripting

Copy subsequent contents of a file from first occurance of grep

There is a file which logs all errors and alerts of the database called alert log. I have a requirement as follows: 1. Check the current date and search for the first occurance of the current date in the alert log. 2. As soon as the first occurance is found, copy the subsequent contents... (5 Replies)
Discussion started by: sunpraveen
5 Replies
Login or Register to Ask a Question