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