LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-11-2008, 11:57 AM   #1
zest n zeal
LQ Newbie
Registered: May 2007
Posts: 18

Rep: Reputation: 0
Can you use grep / awk on variables instead of files?

What I want to do is check if a pattern is found in a string variable. I'm clearly missing either a very useful command or something more even more fundamental, i.e, how to get a string variable to be piped into grep instead of a file name.



how can I check if $Y is part of $X

is this possible with grep / awk?

Old 02-11-2008, 12:30 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
How about echo?

[hector ~]$ X='abcdef'
[hector ~]$ Y='cd'
[hector ~]$ echo $X | grep "$Y"
Old 02-11-2008, 12:37 PM   #3
zest n zeal
LQ Newbie
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
honest I was trying....

can't believe it was that simple



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use grep inside awk? Helene Programming 10 09-29-2015 08:48 PM
Need ideas on how to grep for pattern using awk rahulbgl Linux - Newbie 4 03-05-2007 03:07 PM
Retrieving variables from contents of files using awk or any other bash tool genderbender Programming 8 01-21-2005 03:27 AM
Newbie playing with Awk and Grep Helene Programming 6 04-15-2004 02:08 AM
newbie needs help for grep and awk parker Programming 1 08-12-2003 04:24 AM

All times are GMT -5. The time now is 07:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration