Operating System - HP-UX
1833861 Members
2579 Online
110063 Solutions
New Discussion

Re: Grep - for get words with spaces

 
SOLVED
Go to solution
Manuales
Super Advisor

Grep - for get words with spaces

HI...
When i try to pipe "May 1"i can not do it through grep command:

o=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
echo "cat /var/adm/lp/log | grep ""$o"""
t /var/adm/lp/log | grep May 1

Result:
cat /var/adm/lp/log | grep ""$o""
grep: can't open 1

apparently grep only is taking: May .
how can i do (what coding) for grep command takes "May 1"


thanks.
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: Grep - for get words with spaces

Hi Manuales:

# grep "$0" /var/adm/lp/log

[...and please don't forget to evaulate your other queries :-) ]

Regards!

...JRF...
Manuales
Super Advisor

Re: Grep - for get words with spaces

and if i have to do grep to a variable and not file? how do i have to do it?
James R. Ferguson
Acclaimed Contributor

Re: Grep - for get words with spaces

Hi (again):

# var="May 1"
# thing="May 1"
# echo "${var}" | grep "${thing}"
May 1

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: Grep - for get words with spaces

You seem to have many basic questions about
shell scripts. Have you considered reading
a book on UNIX shell scripting?
Manuales
Super Advisor

Re: Grep - for get words with spaces

your answer helped me a lot:
i had to put double ""

b=$(echo $hola | grep ""${a}"" | grep -v `hostname`)

thanks a lot.
Manuales
Super Advisor

Re: Grep - for get words with spaces

SORRY
THIS WAS THE SOLUTION:

b=$(echo "$hola | grep "\""${a}""\" " | grep -v `hostname`)
Kapil Jha
Honored Contributor

Re: Grep - for get words with spaces

have a look over egrep as well!!
BR,
Kapil
I am in this small bowl, I wane see the real world......