The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with GREP. syndex Shell Programming and Scripting 2 07-11-2007 02:44 PM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 09:49 PM
grep problem svennie UNIX for Dummies Questions & Answers 5 11-08-2004 04:29 AM
Grep Problem lesstjm Shell Programming and Scripting 2 10-27-2004 11:13 AM
Grep problem odogbolu98 Shell Programming and Scripting 3 02-18-2003 03:53 PM

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 09-05-2001
xiamin xiamin is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 64
grep problem

Hi

I would like to know wheather there is anyway to pass a variable to grep argument like this

grep "$myvar" $myfile

i would put this in a function and then call this function by setting different values to myvar and myfile.

is this possible at all.

regards
Hrishy
  #2 (permalink)  
Old 09-05-2001
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584

Yeah, give it a shot, let us know if you have any problems with it! I'm pretty sure what you're describing will work - I have written similar scripts in the past.
  #3 (permalink)  
Old 09-05-2001
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
try single quotes.
  #4 (permalink)  
Old 09-06-2001
xiamin xiamin is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 64
do u folks mean this

Hi

Do you mean to say i can do this using the following.

grep '$myvar' $myfile

regards
Hrishy
  #5 (permalink)  
Old 09-06-2001
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
you could try it. but from what i recall. by default grep will take 2 arguemnts. and if the argument is part of the metacharter set it ie your "$" will make the next charters a variable.

First: try without any quotes. if that does not work try w/ single quotes around each variable.

also makesure you echo your variable befor the grep statement (just for testing) to make sure you are passing information to the variable.
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 08:11 AM.


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