Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
#!/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?

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
show 3 more comments

1 Answer

up vote 0 down vote accepted

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
share|improve this answer
add comment

Your Answer

 
discard

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