Hi,
Is there any other command echo does.
if [ `echo $line|grep "^$companyHdrRecord"| wc -l` -ne 0 ]
I am doing this operation for each line in my file. So its taking very long time to process more than 1000 records.
Is there any alternative way to write the above if statement
vino
March 5, 2008, 4:30am
2
senthil_is:
Hi,
Is there any other command echo does.
if [ `echo $line|grep "^$companyHdrRecord"| wc -l` -ne 0 ]
I am doing this operation for each line in my file. So its taking very long time to process more than 1000 records.
Is there any alternative way to write the above if statement
Perhaps this. Not tested tho'
while read line
do
if [[ $line == "$companyHdrRecord*" ]] ; then
echo $line
fi
done < input.txt
Dhruva
March 5, 2008, 6:25am
3
I guess the problem might be the way you are using loop to get lines one by one.
if you are using loop like
cat filename| while read line
do
.....
.....
done
then instead use the below method
while read line
do
...
...
done < filename
This will reduce your loop proccessing time.
katlan
March 5, 2008, 7:16am
4
Hi,
grep "^${companyHdrRecord}" inputfile| while read line
do
#Operations
echo $line
done
You might want to read "12 ways to parse a file" about the topic.
bakunin
Dhruva
March 5, 2008, 8:12am
6
Those 12 ways to parse a file is really good stuff.I would like to thanks google for sharing with all of us.(Before that i never given thought which one is better)
The method i suggested is one of those 12 ways and it is claimed to be one of the two better performers.