LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can you use grep / awk on variables instead of files? (https://www.linuxquestions.org/questions/linux-newbie-8/can-you-use-grep-awk-on-variables-instead-of-files-620333/)

zest n zeal 02-11-2008 11:57 AM

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

anomie 02-11-2008 12:30 PM

How about echo?

Code:

[hector ~]$ X='abcdef'
[hector ~]$ Y='cd'
[hector ~]$ echo $X | grep "$Y"
abcdef


zest n zeal 02-11-2008 12:37 PM

honest I was trying....
 
can't believe it was that simple

thanx


All times are GMT -5. The time now is 11:15 AM.