3
#!/bin/sh
if [ $# -ne 8 ]; then
        echo "Usage: sh `basename $0` YYYYMMDD hour min masterid account destination filename forward|backward";
        exit 1;
fi

day=${1}
hour=${2}
min=${3}
masterid=${4}
account=${5}
destination=${6}
file=${7}
if [ "${8}" == "backward" ]; then
        backward="true";
fi

if [ "${backward}" != "true" ]; then
        awk -v day=${day} -v hour=${hour} -v min=${min} -v masterid=${masterid} -v account=${account} -v destination=${destination} -f /var/tmp/selfCross.awk /koba/c/dumper/${file}
else
        tac "/koba/c/dumper/${file}" | awk -v day=${day} -v hour=${hour} -v min=${min} -v masterid=${masterid} -v account=${account} -v destination=${destination} -f /var/tmp/selfCross.awk
fi

if backward != true, it is working fine. But, tac is somehow not working what should I do? It is returning immediately. What am I doing wrong in the above script?

  • Does tac, the binary, prints the reverse of the file on shell prompt? Are you sure the column positions would not change when the file is catenated reversely for awk to parse correctly. – Nikhil Mulley Jan 11 '12 at 16:32
  • My bad, it is working fine. sorry all, about the trouble. – user14039 Jan 11 '12 at 16:35
  • ok. What was the problem with the code in the question and what was the fix. Perhaps, you should just write your own answer in the answer field. Admins here will have the question closed thereafter. – Nikhil Mulley Jan 11 '12 at 16:36
  • awk script doesn't handle scenarios when file is sent in reverse, fixed it and it worked fine. Also, it is saying you can self-answer in 7 hours. I will do that later. – user14039 Jan 11 '12 at 16:47
  • Not directly relevant, but you forgot to quote ${file} in the awk line. – Kevin Jan 11 '12 at 17:58
0

not an answer, but a tip: use "true" and "false" commands instead of testing for string equality:

backwards=false
if [[ some condition ]]; then backwards=true; fi

if $backwards; then
  do something
else
  do something else
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy