LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
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.

i.e.,

X=abcdef
Y=cd

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

is this possible with grep / awk?

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

Rep: Reputation: Disabled
How about echo?

Code:
[hector ~]$ X='abcdef'
[hector ~]$ Y='cd'
[hector ~]$ echo $X | grep "$Y"
abcdef
 
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

thanx
 
  


Reply


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
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
Can I use grep inside awk? Helene Programming 6 04-27-2004 12:58 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 12:52 AM.

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