Need help with 2 line unix script

envy me

Golden Member
Nov 5, 2005
1,000
0
0
I need something very simple yet I cannot get the syntax correct:


assuming :

date // will return a value of Mon Oct 6 22:58:56 EDT 2008

and


date | awk '{print $2,$3}' // will return a value of Oct 6

I would like to do a grep of that value surrounded by single quotes. i.e. 'Oct 6'

and use it in the following way:

ls -ltrR /TEST_Logs/ | grep < date | awk '{print $2,$3}'

essentially I want to list the TEST_Logs directory and all subdirectories and filter it on the date, but it has to be in single quotes because it is 2 words. So my 2 problems are:

1. How do I redirect the date/awk command into a grep?

and

2. What must I change in my awk command to include single quotes?


i.e.

ls -ltrR /TEST_Logs | grep 'Oct 6'

any help is much appreciated.
 

dinkumthinkum

Senior member
Jul 3, 2008
203
0
0
What you want is backquotes, to include the output of a command on the command-line.

But, have you considered using a more apt tool instead, like "find"?

find /TEST_Logs/ -newermt `date`

see man 'find' for the -newerXY option, or other.
 

envy me

Golden Member
Nov 5, 2005
1,000
0
0
the -newerxy option is not available for the find command for the shell we are using.

so I can do something similar to

ls -ltrR /TEST_Logs/ | grep < `date | awk '{print $2,$3}'`

but that will do:

ls -ltrR /TEST_Logs/ | grep Oct 6

I need it to do:

ls -ltrR /TEST_Logs/ | grep 'Oct 6'

So all I need is to be able to include the single quotes in my awk command but I've tried enclosing them in double quotes: awk '{print "'",$2,$3,"'"}' but that did not work.

 

envy me

Golden Member
Nov 5, 2005
1,000
0
0
this is the best I could figure out. It's not neat but it works:

echo "'"`date | awk '{print $2,$3}'``echo "'"`
 

envy me

Golden Member
Nov 5, 2005
1,000
0
0
Now I have combined them both but they do not work.... This is really confusing and irritating. Here's what I got:

ls -ltrR /TEST_Logs/ | grep `echo "'"``date | awk'{print $2,$3}'``echo "'"`
 

dinkumthinkum

Senior member
Jul 3, 2008
203
0
0
What's wrong with "`date | awk '{print $2, $3}'`" ?
You can put single quotes inside of double quotes.