The UNIX and Linux Forums  


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
Shell Programming and Scripting nivas Shell Programming and Scripting 20 02-27-2008 06:36 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 21 02-25-2008 06:27 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 2 02-20-2008 02:59 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 14 02-20-2008 02:07 AM
Shell scripting & programming languages aloysius1001 UNIX Desktop for Dummies Questions & Answers 1 02-19-2002 12:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Shell Programming and Scripting

Hi

Iam using grep command as follows in my script

read_file1()
{
cat file1.txt | while read line
do
grep $line file2.txt >> out.txt
done
}
read_file1

This way the performance is very slow. We are having lacks of records in file1 and file2

how can i improve the performance.
  #2 (permalink)  
Old 02-13-2008
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
You can use the '-f' feature of the grep command to do this. I don't know how much faster it will be.

For example, if you have files named file1.txt and file2.txt (as in your example), then

grep -f file1.txt file2.txt >> out.txt

should do the job. Note that each line is a pattern.
  #3 (permalink)  
Old 02-13-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
No this command is not working.


what is pattern. hope my file is not a pattern
  #4 (permalink)  
Old 02-13-2008
TonyLawrence TonyLawrence is offline
Registered User
  
 

Join Date: Sep 2007
Location: SE Mass
Posts: 147
Quote:
Originally Posted by nivas View Post
Hi

Iam using grep command as follows in my script

read_file1()
{
cat file1.txt | while read line
do
grep $line file2.txt >> out.txt
done
}
read_file1

This way the performance is very slow. We are having lacks of records in file1 and file2

how can i improve the performance.
I'm not going to write the code for you, but what I think you want is to take advantage of "egrep" (or "grep -E" if gnu).

For example,

grep -E "one|two|three" yourfile

will find any of "one" "two" or "three" in "yourfile"

By the way, GNU grep has a lot of neat stuff: grep in depth
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 12:51 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