The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
alternate lines pstanand Shell Programming and Scripting 6 03-18-2008 11:14 PM
Alternate to pinging boxes benefactr UNIX for Advanced & Expert Users 5 12-13-2007 04:40 AM
Alternate Logon Method? earnstaf Forum Support Area for Unregistered Users & Account Problems 2 08-16-2007 03:54 PM
Alternate command for cut Mohammed Shell Programming and Scripting 2 10-20-2006 07:42 AM
alternate lines from two files SummitElse UNIX for Dummies Questions & Answers 1 02-24-2005 09:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-05-2008
senthil_is senthil_is is offline
Registered User
  
 

Join Date: Sep 2007
Location: singapore
Posts: 35
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 (permalink)  
Old 03-05-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by senthil_is View Post
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 (permalink)  
Old 03-05-2008
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
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 (permalink)  
Old 03-05-2008
katlan katlan is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 4
Another

Hi,

grep "^${companyHdrRecord}" inputfile| while read line
do
#Operations
echo $line
done
  #5 (permalink)  
Old 03-05-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
You might want to read "12 ways to parse a file" about the topic.

bakunin
  #6 (permalink)  
Old 03-05-2008
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0