I have an AWK script that is being called within a shell script.
The shell script takes a directory as argument and runs the AWK script in that directory (and all subdirectiories) on a specific file (always the same file name).
This file somtimes has lines that are longer than 3,000 bytes and then my AWK script exits with an error message.
I can get rid of the lines that are too long with an extra SED script, but that script is quite slow, because it needs to unzip the original file, make a file containing only the offending lines, another file without the offending lines, backup the original file and finally zip all 3 files again.
I want my script to run normally until the AWK scripts exits with the error and then (and only then) run the SED script and afterwards re-run the AWK script.
Since I am new to shell scripts I have no clue how to get the return/exit code of a script.
Any help is gretly appreciated.
-----SHELL SCRIPT: (relevant parts) HP-UX-11.00
cd $1
find . -name INPUTFILE.gz | while read filename
do
gzcat $filename | awk -f AWKFILE
done
cd -
-----
-----SED SCRIPT:
cd $1
gunzip INPUTFILE.gz
sed -n '/PATTERN/p' INPUTFILE >> OFFENDINGFILE
sed '/PATTERN/d' INPUTFILE >> GOODFILE
mv INPUTFILE BACKUPFILE
mv GOODFILE INPUTFILE
gzip -9 INPUTFILE BACKUPFILE OFFENDINGFILE
cd -
-----
The shell script takes a directory as argument and runs the AWK script in that directory (and all subdirectiories) on a specific file (always the same file name).
This file somtimes has lines that are longer than 3,000 bytes and then my AWK script exits with an error message.
I can get rid of the lines that are too long with an extra SED script, but that script is quite slow, because it needs to unzip the original file, make a file containing only the offending lines, another file without the offending lines, backup the original file and finally zip all 3 files again.
I want my script to run normally until the AWK scripts exits with the error and then (and only then) run the SED script and afterwards re-run the AWK script.
Since I am new to shell scripts I have no clue how to get the return/exit code of a script.
Any help is gretly appreciated.
-----SHELL SCRIPT: (relevant parts) HP-UX-11.00
cd $1
find . -name INPUTFILE.gz | while read filename
do
gzcat $filename | awk -f AWKFILE
done
cd -
-----
-----SED SCRIPT:
cd $1
gunzip INPUTFILE.gz
sed -n '/PATTERN/p' INPUTFILE >> OFFENDINGFILE
sed '/PATTERN/d' INPUTFILE >> GOODFILE
mv INPUTFILE BACKUPFILE
mv GOODFILE INPUTFILE
gzip -9 INPUTFILE BACKUPFILE OFFENDINGFILE
cd -
-----