1834934 Members
2866 Online
110071 Solutions
New Discussion

Re: export with grep

 
SOLVED
Go to solution
Stephen Badgett
Regular Advisor

export with grep

When doing a export with an imbedded “grep” I seem to lose a space within the grep command…

here> export now="/orca/oracle/admin/DRX/bdump/*.trc|grep \"May 9\""
here> echo $now
/orca/oracle/admin/DRX/bdump/*.trc|grep "May 9"

What do I need to do to fix this? – I get the same response on HP-UX and
Not as is, is now
14 REPLIES 14
Steven E. Protter
Exalted Contributor

Re: export with grep

As far as grep goes, I use it like this:

netstat -an | grep ":80 "

No special characters needed.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stephen Badgett
Regular Advisor

Re: export with grep

I am not sure I am following what you stated ...

Here is the example why I use "\" ...

$ export now=/orca/oracle/admin/DRX/bdump/*.trc|grep "May 9"
$ echo $now
/orca/oracle/admin/DRX/bdump/*.trc|grep May
$ export now="/orca/oracle/admin/DRX/bdump/*.trc|grep \"May 9\""
$ echo $now
/orca/oracle/admin/DRX/bdump/*.trc|grep "May 9"

It just seems like I loose all the spaces between May and 9 -- The reason I am doing this is that the date is right justified and I need one imbedded space between the month and day if the day is lees then a 2 digit number


Example:

-rw-r----- 1 oracle dba 750 May 3 17:33 /orca/oracle/admin/DRX/bdump/drx_s000_29419.trc
-rw-r----- 1 oracle dba 1431 May 19 02:07 /orca/oracle/admin/DRX/bdump/drx_s000_32267.trc
I might be going at this wrong but it does seem to be something simple that is not working the way I would like.

Not as is, is now
Gregory Fruth
Esteemed Contributor

Re: export with grep

In the examples you provided it looks like
there *is* a space between May and 9. What
exactly are you going to do with $now besides
echo it? This is probably a shell quoting
problem, not a problem with grep itself.
Volker Borowski
Honored Contributor
Solution

Re: export with grep

Hi,

since you escaped the inner double quotes, the expansion eliminates the multiple whitespaces. Use single quotes without escaping them inside:
export now="/orca/oracle/admin/DRX/bdump/*.trc|grep 'May 9'"

Hope this fixes it (no system to check available now)
Volker
Stephen Badgett
Regular Advisor

Re: export with grep

here is the sh script I am trying to create/test ... attached too


#export now="/orca/oracle/admin/DRX/bdump/*.trc|grep \"`date '+%b %e'`\""
export now="/orca/oracle/admin/DRX/bdump/*.trc|grep \"May 9\""

echo $now
ls -l $now
if test -r '$now'
then
echo "TRC FILE ON DEVLOAD - " > /home/sbadgett/data/trc-list
# ls -l /orca/oracle/admin/DRX/bdump/*.trc|grep "$now" >> /home/sbadgett/data/trc-list
ls -l /orca/oracle/admin/DRX/bdump/*.trc|grep "May 9" >> /home/sbadgett/data/trc-list
echo "end of report" >> /home/sbadgett/data/trc-list
mail -s "!!! DEVLOAD trc file is there !!!" sbadgett@pharmcomp.com < /home/sbadgett/data/trc-list
fi

Not as is, is now
Stephen Badgett
Regular Advisor

Re: export with grep

I have tried ...
export now="/orca/oracle/admin/DRX/bdump/*.trc|grep 'May 9'"

I still get the same results
Not as is, is now
Volker Borowski
Honored Contributor

Re: export with grep

Hi,

what is your OS and what is your shell ?

I just verified this behavior on Linux with bash, but the environment Variable HAS stored the additional blanks! They are just not re printed, when the variable is expanded, no idea why !
I have used variable with blanks in content on Solaris today (!), this is why I suggested it this way, but now on Linux ....

Check, after "now" is set to content with several Blanks with

env | grep now

...should show the blanks !

Verify with
if [ "$now" = "your_content" ] ; then echo true; fi

with single blanks and correct number of blanks.

Looks like the forum does the same elimination !

I am confused
Volker

Robert Salter
Respected Contributor

Re: export with grep

Looks like you're trying to capture the full path to the trc file with a certain time stamp. Try
export now=`ll /orca/oracle/admin/DRX/bdump/*.trc|grep "May 9"|awk '{print $9}'`
Time to smoke and joke
Stephen Badgett
Regular Advisor

Re: export with grep

Volker Borowski -- Yes I did see spaces -- so the test condition should work. I was wondering why the spaces would be removed with in " "'s. Well as long as the test condition works I am fine
Not as is, is now
Volker Borowski
Honored Contributor

Re: export with grep

Steve,

if the variable has the blanks,
try
..... | grep -e "$now"

Volker
Volker Borowski
Honored Contributor

Re: export with grep

OK, and

echo -E "$now"

does the trick on Linux at least :-)

Nice nut to crack
Volker
Stephen Badgett
Regular Advisor

Re: export with grep

Ok - got it to work ...

export x="`date '+%b %e'`"
export now="`/bin/ls -l /orca/oracle/admin/DRX/bdump/*.trc|grep \"$x\"|cut -b 50-`"

echo "test"
echo $now
if test -e $now
then
echo "TRC FILE ON DEVLOAD - " > /home/sbadgett/data/trc-list
/bin/cat $now >> /home/sbadgett/data/trc-list
echo "end of report" >> /home/sbadgett/data/trc-list
mail -s "!!! DEVLOAD trc file is there !!!" sbadgett@pharmcomp.com < $now
else
echo none today
fi
Not as is, is now
Stephen Badgett
Regular Advisor

Re: export with grep

The final copy ...

export x="`date '+%b %e'`"
export now="`/bin/ls -l /orca/oracle/admin/DRX/bdump/*.trc|grep \"$x\"|cut -b 50-`"

if test -e $now
then
mail -s "!!! DEVLOAD trc file is there !!!" sbadgett@pharmcomp.com < $now
else
echo none today
fi
Not as is, is now
Stephen Badgett
Regular Advisor

Re: export with grep

Thanks for all your help -- I mean ALL you help


Stephen
Not as is, is now