SOLVED: Refining an awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SOLVED: Refining an awk command
# 1  
Old 02-16-2011
SOLVED: Refining an awk command

I have a file (file1) with in the below format

HTML Code:
ST*820*212121
BPR*C*213212.20*C*212*CCD*01***01*071000013*DA*321321*101208
TRN*1*21321321*13213
N1*PR*3232. dff. SYS.*91*3232
ENT*1
N1*PE* 2132121321
RMR*TN*234456677888**192387.20*192387.20
REF*IV*234456677888*213213 3213 UNI
DTM*003*101122
RMR*TN*835435435323**1*1
SE*000010*3213213
I have the below mentioned awk command to fetch the RMR loop (that is ) with an account number (234456677888) as the reference.

$acct is 234456677888

HTML Code:
awk ' /'"$acct"'/&& /RMR/{print;flag=1;next} (/RMR/ ||  /ENT/)  {flag=0} flag { print }' $tmp/file1
The above command was fetching me the RMR loop until it finds the next RMR
HTML Code:
RMR*TN*234456677888**192387.20*192387.20
REF*IV*234456677888*213213 3213 UNI
DTM*003*101122
Now the problem is when the same account number is present in the row next to the RMR (REF*IV*234456677888*213213 3213 UNI), the same command returns a different result as shown below.
HTML Code:
RMR*TN*234456677888**192387.20*192387.20
Can anyone suggest what should I do to get the same result as I was getting earlier

---------- Post updated at 06:55 AM ---------- Previous update was at 06:44 AM ----------

I could fix this by adding RMR.* before the $acct in the script.

Last edited by radoulov; 02-16-2011 at 06:41 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with refining script

Happy new year all! I would like to ask for some assistance refining the script I have put together below. I am a noob with bash scripting and still getting used to all the options available originally coming from a windows background couch, couch... Now I am more than happy in NIX world :b::)... (13 Replies)
Discussion started by: Simplify
13 Replies

2. UNIX for Dummies Questions & Answers

[Solved] awk oddity

I have to apologize for my ignorance so this question is probably stupid. How does awk process a file? Does it read from top of input file to end of file going line by line? Yoda helped me create an awk script that helps me parse the named.conf file and output it into a .csv file but when... (8 Replies)
Discussion started by: djzah
8 Replies

3. UNIX for Dummies Questions & Answers

[Solved] awk FS

I have a script which uses awk to read from a file seperated with commas, although saved as a .conf file. awk -F, '{print $3}' it is meant to pick up "a label here" (for example) But instead return "a" Problem is that although the command does recognise the comma seperation it still... (1 Reply)
Discussion started by: Pedro72
1 Replies

4. UNIX for Dummies Questions & Answers

[Solved] To the power of using awk

Hi Guys, I got stuck to a a point where I need to find the value for (4 to the power of -2 upto 8 places after decimal .... 4^(-2) ; the result I need is upto 8 places after decimal. How is that possible? Thanks a lot!! (2 Replies)
Discussion started by: Indra2011
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Help with awk

Hi All, I have been using the below syntax in unix and it has been working fine, Later when we migrated to Linux by having folder wise pemission its not working fine. So can you let us know where the list file could be created ? awk '/^XXX/{key=$0;print > "list";next} /^YYY/ {print... (4 Replies)
Discussion started by: secretsanta.rci
4 Replies

6. Shell Programming and Scripting

[Solved] awk command to read sequentially from a file until last record

Hello, I have a file that looks like this: Generated geometry (...some special descriptor) 1 0.56784 1.45783 -0.87965 8 1.29873 -0.8767 1.098789 ... ... ... ... Generated geometry (....come special descriptor) ... .... ... ... ... ... ... ... and... (4 Replies)
Discussion started by: jaldo0805
4 Replies

7. Shell Programming and Scripting

Solved: AWK SED HELP

Hi, I need to process a file as below. Could you please help to achieve that using awk/sed commands. Input file: --------------- AB | "abcdef 12345" | 7r5561451.pdf PQRST | "fghfghf hgkjgtjhghb ghhgjhg hghjghg " | 76er6ry.pdf 12345 | "fghfgcv uytdywe bww76 jkh7dscbc 78 : nvchtry hbuyt"... (0 Replies)
Discussion started by: viveksr
0 Replies

8. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

9. Shell Programming and Scripting

Refining if loops using sed/awk

hi All, I have the following two requirements: case 1: In a file i have the below code: if ((a>b)) a=b; else a = c; by using some means i need to convert the line to the following output: Output required: case 2: In a file i have the below code: if (a>b) a=b; else a... (4 Replies)
Discussion started by: engineer
4 Replies

10. Shell Programming and Scripting

can this been solved with awk and sed?

Hi Masters, ___________________________________________________________________________________ Group of orthologs #1. Best score 3010 bits Score difference with first non-orthologous sequence - yeast:3010 human:2754 YHR165C 100.00% PRP8_HUMAN 100.00%... (16 Replies)
Discussion started by: mskcc
16 Replies
Login or Register to Ask a Question