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
awk as grep with variables pp56825 Shell Programming and Scripting 7 02-15-2008 09:34 AM
combined stdout & stderr slavam UNIX for Advanced & Expert Users 11 10-12-2007 04:06 PM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 03:59 AM
FIND/CHMOD combined smoother Shell Programming and Scripting 33 09-22-2007 06:59 AM
Using grep with variables gettingstarted Shell Programming and Scripting 2 02-04-2005 10:52 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-21-2006
cin2000 cin2000 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 30
grep command with combined variables in Ksh

Hi,
I'd like to grep two variables that are seperated with one space in ksh.
var1="Feb"
var2="09"

I tried to grep "$var1 ""$var2" /usr/file

It turn into grep Feb 09 /usr/file when it runs.

I got error.

Can some one help me with this one?

Thanks a lot for your help!
  #2 (permalink)  
Old 02-21-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Why dont you try putting the variables together inside the double quotes instead of quoting them seperately? That will get you the grep command that you are looking for.
  #3 (permalink)  
Old 02-21-2006
rhfrommn rhfrommn is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2003
Location: Minnesota
Posts: 424
Or if you want to find both strings even when they are not right next to each other, pipe your greps together, like this:

grep Feb /usr/file | grep 09

This would find it even if the exact text isn't Feb 09 but both pieces are on the same line. For example, it would find "Today is Feb 09" but it would also find "My grandfather was born in February 1909". The method blowtorch suggested is better if you want to find just the exact string Feb 09.

Ok, I just noticed the line where you said they need to be separated by one space, so I guess blowtorch's method is better. But I might as well leave this here for more information since I bothered to type it in. :-)
  #4 (permalink)  
Old 02-21-2006
DogDay's Avatar
DogDay DogDay is offline
Registered User
  
 

Join Date: Jun 2005
Location: /dev/null
Posts: 83
Too many quotes.

grep "$var1 $var2" filename
  #5 (permalink)  
Old 02-22-2006
cin2000 cin2000 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 30
grep in ksh

It worked.
Thanks everybody!
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 01:39 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