Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
if [ $# -ne 8 ]; then
        echo "Usage: sh `basename $0` YYYYMMDD hour min masterid account destination filename forward|backward";
        exit 1;

if [ "${8}" == "backward" ]; then

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}
        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

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?

share|improve this question
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
up vote 0 down vote accepted

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

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

if $backwards; then
  do something
  do something else
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.