Alternate way for echo.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternate way for echo.
# 1  
Old 03-05-2008
Alternate way for echo.

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
# 2  
Old 03-05-2008
Quote:
Originally Posted by 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'
Code:
while read line
do
  if [[ $line == "$companyHdrRecord*" ]] ; then
    echo $line
  fi
done < input.txt

# 3  
Old 03-05-2008
I guess the problem might be the way you are using loop to get lines one by one.

if you are using loop like
Code:
cat filename| while read line
 do
 .....
 .....

 done

then instead use the below method

Code:
while read line
 do
 ...
 ...
 done < filename

This will reduce your loop proccessing time.
# 4  
Old 03-05-2008
Another

Hi,

grep "^${companyHdrRecord}" inputfile| while read line
do
#Operations
echo $line
done
# 5  
Old 03-05-2008
You might want to read "12 ways to parse a file" about the topic.

bakunin
# 6  
Old 03-05-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alternate for sed -i in AIX

Experts, At the moment I am working in AIX box where sed -i is not available. My requirement is as below Two files file1 and file2. file1 contains the IP address, its count. file2 contains the Hostname and its corresponding IP address. I would like get the IP address replaced with the apt... (7 Replies)
Discussion started by: sathyaonnuix
7 Replies

2. HP-UX

Alternate for wget

Hi, Whats the alternate for wget in HP-UX ? (4 Replies)
Discussion started by: mohtashims
4 Replies

3. Shell Programming and Scripting

uniq not working, so any alternate?

Hi, I have these two files . file1 /home/prog/bug/perl /home/prog/bug/ant /home/prog/bug/make /home/prog/bug/gen /home/prog/bug/tiff file2 /home/prog/bug/make /home/prog/bug/gen i want a output file which should contain file1-file2 (2 Replies)
Discussion started by: debu182
2 Replies

4. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

5. Shell Programming and Scripting

Wants alternate to the Sleep option??

I am new to Shell Scripting and I need help to write the following script in a different format... This is the current script: #!/usr/bin/ksh environment=rms export environment . $AW_HOME/RETEK/exec/RETEK_ENVAR ls -ltr $MMPOS/RTLOG* | tr -s " " | cut -d " " -f9... (20 Replies)
Discussion started by: satyajit007
20 Replies

6. Solaris

Self ssl alternate in Solaris

Instead of using an external Certification Authority CA such as Verisgn, in windows I have been told there is something called self ssl ( The server is its own Certification Authority) In Solaris is there such an alternate? In need it for apache. Much appreciate for any guidence. Thanks (2 Replies)
Discussion started by: Tirmazi
2 Replies

7. Shell Programming and Scripting

alternate lines

Hi, I'm new to Unix. I want to read the all the lines from a text file and write the alternate lines into another file. Please give me a shell script solution. file1 ----- one two three four five six seven newfile(it should contain the alternate lines from the file1) ------- one... (6 Replies)
Discussion started by: pstanand
6 Replies

8. Shell Programming and Scripting

Alternate command for cut

Hello, I have a string below DUMMY=1,2,3,4,5,6 I want to extract fields 1-3 and put it as under in a file 1,2,3 I can do this using cut like below echo $DUMMY | cut -d, -f1-3 But I would be processing more than 15000 such entries and I found that "cut" was using more CPU. So anyone... (2 Replies)
Discussion started by: Mohammed
2 Replies

9. UNIX for Dummies Questions & Answers

alternate lines from two files

A basic request two files want to combine them but on alternate lines (1 Reply)
Discussion started by: SummitElse
1 Replies
Login or Register to Ask a Question