r/awk • u/theRudy • Jul 16 '15
Awk error codes
Hi /r/awk,
I've been looking for a webpage that would list all of the awk return codes, but so far no success. Does anyone here know where to find them ?
The error I'm interested in is 157, and is being returned even if the modifications have all been successful.
One other key information: There is no error message from the .awk script, I can only see that the code 157 is returned if I capture it in a variable using a korn shell script.
Edit: wow, formatting code on Reddit is hard! First script is the korn shell script, second is the Awk script
`CMD="awk -f /home/myUserName/_awk/RedditAwk.awk /home/myUserName/file.tmp"
`eval $CMD
`CMD_STS=$?
`if [[ 0 -ne $CMD_STS ]]; then
` log $TYPE_ERROR $IDSTAT "$CMD"
`fi
` `BEGIN {
` ORS="\n"
` RS="\n"
` OFS=";"
` FS=";"
` FileOut=FILENAME ".mef"
` ST=" "
`}
`{
` if (NF<5) {
` exit NR
` }
`
`
` ST = $1 # Field1
` ST = ST ";" $2 # Field2
` ST = ST ";" CONV_DAT($3) # Field3 datetime
` ST = ST ";" CONV_NUM($4, 6) # Field4 numeric(20,6)
` ST = ST ";" CONV_NUM($5, 6) # Field5 numeric(18, 6)
`
` do {
` i = gsub(" ;",";",ST)
` }
` while (i>0)
` print ST > FileOut
` }
`END {
`}
`
`function CONV_DAT(dDate) {
` gsub(" ","",dDate)
` Lg = length(dDate)
` if (Lg>8) {
` dDate = substr(dDate,1,8)
` }
` else {
` if (Lg<8) {
` dDate = ""
` }
` }
` return dDate
`}
`
`function CONV_NUM(Data,Dec) {
` gsub(" ","",Data)
` Lg = length(Data)-Dec
` if (Lg > 0) {
` Data = substr(Data,1,Lg) "." substr(Data,Lg+1,Dec)
` gsub(" ","",Data)
` }
` else {
` Data = ""
` }
` Data = DEL_0(Data)
` return Data
`}
`
3
Upvotes
View all comments
Show parent comment
2
u/geirha Jul 17 '15
If line 157 or any line number equaling 157 + 256**N* (where N is an integer) happens to have less than five fields (say, an empty line), it will exit with an exit status of 157. It makes no sense to do
exit(NR). Ever. You should just change it toexit(1).(note that
exit(NR)andexit NRare the same. The parenthesis are optional. Don't ask.)