Need help for Cut Command

Hi All,
Greetings..
I am having a Line of 1600 characters in which each specifi fields have some values. For example 1-5 Firstname 6-8 Age and so on..
I am using `expr substr $line 100,7` to get values from the line and store in seperate variables..
The file contains 70000 lines. It is taking 3 hrs to complete the whole file.

Can anyoe suggest me to replace the above substr command with awk or cut command?

Also, Please tell me which one is quicker..substr or cut or awk ?
Please help

Thanks in advance!

Can you post example data, or give a more detailed breakdown of what you are trying to achieve ?

i.e. Are the fields space seperated / how many fields are you trying to extract etc.

Hi ,
Thanks for the reply..I am able to use the cut -c command and able to achieve my requirement. But Now I am facing a problem for sed -e command with cut command.

If I use

echo "SPACE    " | cut -c 1-10 

I will get the output as "SPACE "
I donot need the white spaces followed to be printed. So I am using the command as

echo "SPACE     " | cut -c 1-10 | sed -e 's/*$//g'

. But eventhough i am using the sed command piped with cut -c ,the white spaces are not removed. Can anyone help on this.

Thanks in advance

I thin awk will do the job alot faster. You can use the substr function in awk to parse out your data.

Your forgot to give a space:
echo " SPACE " | sed -e 's/ *$//g' # Removes all spaces at the end only
echo " SPACE " | sed -e 's/ //g' # Removes all spaces. Front also

xx=" SPACE "
echo $xx # No space
echo "$xx" # With space

Thanks a lot.. After adding a space it is working properly.

sed -e 's/ *$//g'

Speed ? Use only awk substr+gsub or only shell builtin. Mixed shell + awk/cut/sed is slow.
Shell:

#!/bin/ksh
#!/bin/bash
while read line
do
     f1=${line:0:5}  # 1st char index is 0   {var:pos:len}
     f1=${f1%% *}     # remove last spaces
     f2=${line:5:3}
     f2=${f2%% *}     # remove last spaces
     echo "<$f1><$f2>"
done < inputfile

Awk:

awk '{
f1=substr($0,1,5)
f2=substr($0,6,3)
gsub(/ *$/,"",f1)
gsub(/ *$/,"",f2)
print "<" f1 "><" f2 ">"
} ' inputfile

Thanks a lot kshji...
Awk file is processing a lot lot lot faster..
Can anyone please tell me how to call a function inside a awk file.?

Thanks in advance

#!/usr/bin/awk -f

function sum(a,b)
{
   return a+b
}

{  x=sum($1,$2)
   print $0,x
}