I tried with this code.. but its not working.. the script is not terminating.. and the log file is empty..
#!/bin/ksh
for name in `cat data.txt`
do
cat $name |cut -f2,3,4,5,6,7,8,9|tr '\t' '|' > processed_data.txt
done
if [ $? -eq 0] ; then echo " Prcocessing completed."
else echo "script failed"
fi
Not sure of your problem, but spacing could have been an issue around certain commands. At any rate, the following command and result is what I just got (I am using bash):
You don't cat individual lines of data; cat expects a file name argument. But looping over individual lines is pretty pointless anyway, as both cut and tr can handle multi-line data. Simply replacing tabs with pipes and discarding the first three characters should suffice, right?
By the by, it's more elegant to run the command inside the if:
if tr '\t' '|' <data.txt | cut -c3- >processed_data.txt; then
echo Success
else
echo Failure
fi
The printing of a message when the script is already done is not very useful as such; the user will see that the script has finished when the prompt returns, and the exit code will indicate the status. (Neither cut not tr can really fail, unless you have invalid syntax, so the only possible failure I see here is a disk or file system failure.)