Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
Please find the script below:
the functionality of the script is , it picks up files like A.B.C.D.E where D->UNCRYPTED/ZIP from $FILETEMP1 directory and then removes the D.E and moves A.B.C to a specified directory.My requirement now is how to replace the cut command with AWK.
for fic in `cat $UEXTMP/$FILETEMP1| grep "\.UNENCRYPTED"|grep -v \.ZIP`
do
if [ -s $UEXDATA_IN/$FOLDER_T04/$fic ]
then
NAME=`echo $fic|cut -f 1-3 -d "."`
mv $UEXDATA_IN/$FOLDER_T04/$fic $UEXDATA_IN/$FOLDER_T04/$FOLDER_UNZIP/$NAME
fi
doneThanks in advance for your help.

NAME=`echo $fic | awk -F"." '{print $1 $2 $3}'
awk -F"." uses . as field seperator. But if cut is doing all that you want, what;s the big point in using awk ?

Hi ,
Thanks for the info.
Would like to know which is more feasible, cut or awk command?
Regards,
Neeraja

The main difference in the two would be in resources consumed.
I prefer to use the simplest command possible. awk can do so much more that cut, so one would expect cut to be "leaner and meaner". When used in a loop, you are creating and running these processes over and over, so a difference in the two can really add up.
I timed a 1000-iteration loop with both cut and awk, and I sent the output to /dev/null so as not to consume any time going to the screen:
k=1
while [ $k -le 1000 ]
do
echo abcdef | cut -c2,3 > /dev/null
((k=k+1))
donek=1
while [ $k -le 1000 ]
do
echo abcdef | awk '{print substr($0,2,2)}' > /dev/null
((k=k+1))
done$ time ./cut.sh
real 8.6
user 2.8
sys 7.3$ time ./awk.sh
real 11.3
user 3.9
sys 9.0I ran these timings several times to make sure I was getting consistent results. As you can see, with 1000 executions, cut was more efficient on my HP-UX by a significant but not overwhelming margin.
However, this type of test would seem to put a lot of emphasis on process creation (1000 of them) and very little on each process execution. So I decided to time cut and awk on a single long task. I timed the following two commands on a file with 370,000 lines:
cut -c2,3 bigfile > /dev/null
awk '{print substr($0,2,2)}' bigfile > /dev/null
time cut.sh
real 3.9
user 3.5
sys 0.3$ time awk.sh
real 25.5
user 25.0
sys 0.4I ran these multiple times and continued to get similar results. You could have won some money off of me - I would have bet that these times would have been much closer together.

Awk is very slow but if you can't do something easily (or at all) with pipelines of simpler tools, it's still very useful.

Hello Jim,
Thanks a lot for your time and the information you have provided.
Thanks Wolfbone..
Regards,
Neeraja

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |