Guest_imported
New member
- Jan 1, 1970
- 0
Hi ,
I am writing a shell script in which I have to search for a pattern, get the
last occurence of the pattern in a file, read in the next line after the
last such occurence of the pattern, parse in this line so as to get a number
which is between the '<' and '>' marks. Now the script I have written does
this stuff and gets the number in awk . Now how am I to access this same
value outside the awk part. Any help would be appreciated. Here is my wee
script.
#! /usr/bin/ksh
typeset -i count
counter=`grep -c charVerifyFile input.err`
awk ' BEGIN {newcount=0}
/charVerifyFile/ { ++newcount
if (newcount == count )
{ print $0 ; k=NR } }
{if ( NR==k+1 ) { split($0,a,"<"
}; { split(a[2],b,">"
}}
END {print b[1]}' count="$counter" input.err
Here is the sample input file input.err
Exception report - Tue Jan 16 16:07:27 2001
1 charInit. 1000 376 charVerifyFile
[Failed to scan valid # of elements from map file. Line # <32>]
2 charInit. 1000 111 charFile
3 unitTest.c 1000 151 Main
4 charMapInit. 1000 376 charVerifyFile Second occ
[Failed to scan valid # of elements from map file. Line # <37>]
5 charInit. 1000 111 charFile
6 unitTest.c 1000 151 Main
At the end of this stage the variable b[1] contains the desired value which
is 37 from the line
[Failed to scan valid # of elements from map file. Line # <37>]. How do I
access this variable once outside awk.
I am writing a shell script in which I have to search for a pattern, get the
last occurence of the pattern in a file, read in the next line after the
last such occurence of the pattern, parse in this line so as to get a number
which is between the '<' and '>' marks. Now the script I have written does
this stuff and gets the number in awk . Now how am I to access this same
value outside the awk part. Any help would be appreciated. Here is my wee
script.
#! /usr/bin/ksh
typeset -i count
counter=`grep -c charVerifyFile input.err`
awk ' BEGIN {newcount=0}
/charVerifyFile/ { ++newcount
if (newcount == count )
{ print $0 ; k=NR } }
{if ( NR==k+1 ) { split($0,a,"<"
END {print b[1]}' count="$counter" input.err
Here is the sample input file input.err
Exception report - Tue Jan 16 16:07:27 2001
1 charInit. 1000 376 charVerifyFile
[Failed to scan valid # of elements from map file. Line # <32>]
2 charInit. 1000 111 charFile
3 unitTest.c 1000 151 Main
4 charMapInit. 1000 376 charVerifyFile Second occ
[Failed to scan valid # of elements from map file. Line # <37>]
5 charInit. 1000 111 charFile
6 unitTest.c 1000 151 Main
At the end of this stage the variable b[1] contains the desired value which
is 37 from the line
[Failed to scan valid # of elements from map file. Line # <37>]. How do I
access this variable once outside awk.