Computing.Net > Forums > Unix > grep using variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep using variables

Reply to Message Icon

Name: Malcs72
Date: May 15, 2003 at 04:38:00 Pacific
OS: Unix
CPU/Ram: p3
Comment:

Can anyone help with using grep to search a file for a string stored in a variable.

ie
x=20:30
grep $x filename

It works fine when I can manually use the hard code, but I require the use of a stored value.
grep 20:30 filename.

help much appreciated.

thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Ozpay
Date: May 15, 2003 at 06:32:27 Pacific
Reply:

Try this

x=123
grep `echo $x` filenames



0

Response Number 2
Name: nails
Date: May 15, 2003 at 06:36:47 Pacific
Reply:

Hi:

Is this what you are asking for:

x=20:30
str="grep $x filename"
eval $str

Regards,

Nails


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep using variables

Using variable string in AWK www.computing.net/answers/unix/using-variable-string-in-awk/5043.html

To use variables in AWK www.computing.net/answers/unix/to-use-variables-in-awk/8025.html

printing all lines after grep using awk www.computing.net/answers/unix/printing-all-lines-after-grep-using-awk/8491.html