awk command not working from the shell script

Hi,

When i run the below command i am able to get the output.

awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' abc.txt | 
awk '/END DSSUBRECORD/{exit}{print}' |
awk '/Owner/{exit}{print}' | 
awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'

Output:

 Name "file_name",          Prompt "Enter the file name",          ParamType "1"
 Name "file_name1",         Prompt "Enter the file name",          ParamType "1"

============================================================================================================

I want run this command for multiple files. so i wrote a script to check.
When i run this command using a sheel script, it is not working.

I have the below error message:

a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
bp1="awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0'  | 
awk '/END DSSUBRECORD/{exit}{print}' |
awk '/Owner/{exit}{print}' | 
awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'"
echo " "  `$bp1`
a=$(( $a + 1 ))
done
 
 Syntax Error The source line is 1.
 The error context is
                 >>> /BEGIN <<<
 awk: 0602-500 Quitting The source line is 1.

input is a txt file and it is a big file.i tired all the possibilties to skip the '/' and $0 values in the command.
Any help would be appreciated.

Thanks

It would help if you used code tags, you can get them by clicking on the # symbol above the text box you posted your message in.

It is always a good idea to include an excerpt from your input file (Between code tags) that contains at the least some of the lines you are trying to match to; presumably the line begining "BEGIN DSSUBRECORD".

try the below:-

cat awk_1:-

/BEGIN DSSUBRECORD/{c=3;next}c-->0 ; /END DSSUBRECORD/{print}
/Owner/{print}
{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}

---------------------

a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
awk -f awk_1 < infile > out_file &
a=$(( $a + 1 ))
done

:D:D:D:D

Without optimizing the awk code (which I am sure can be done without pipes) you could us a function:

dnsfilter() {
  awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' "$1" |
  awk '/END DSSUBRECORD/{exit}{print}' |
  awk '/Owner/{exit}{print}' |
  awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'
}
a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
  printf " "
  dnsfilter $a1
  a=$(( $a + 1 ))
done

Hi,

Thanks for your help. It is working fine.

dnsfilter() {
  awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' "$1" |
  awk '/END DSSUBRECORD/{exit}{print}' |
  awk '/Owner/{exit}{print}' |
  awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'
}
a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
  printf " "
  dnsfilter $a1
  a=$(( $a + 1 ))
done

I need to pass one more parameter, i tried below passing paramters. It is returning output but not the correct one.

dnsfilter() {
  awk '/BEGIN DSSUBRECORD/{c=3;next}c-->"$1"' "$2" |
  awk '/END DSSUBRECORD/{exit}{print}' |
  awk '/Owner/{exit}{print}' |
  awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'
}
a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
  printf " "
  dnsfilter $a $a1
  a=$(( $a + 1 ))
done

Need help on this.

Thanks

I have tried with many options in unix.

Over all information:
The search pattran contains in the file 'N' times. i want to display 'N' times
I need to pass one more parameter, i tried below passing paramters. It is returning output but not the correct one.

dnsfilter() {
awk '/BEGIN DSSUBRECORD/{c=3;next}c-->"$1"' "$2" |
awk '/END DSSUBRECORD/{exit}{print}' |
awk '/Owner/{exit}{print}' |
awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}'
}
a=0
cnt=2
a1="abc.txt"
while [ $a -ne $cnt ]
do
printf " "
dnsfilter $a $a1
a=$(( $a + 1 ))
done

any help greatly appricated.

Regards,
Suri