Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help: date command breaks in script 1

Status
Not open for further replies.

djr111

Technical User
Joined
Aug 5, 2006
Messages
357
Location
US
Hi,

I need to grep the contents of $SFILE for the month and day.

EG: Dec 16

the example below does not work because it believes %d is a new command. I am not sure how I can overcome this, so I am asking for a little guidance.



/usr/bin/cat $SFILE |grep `date +%b %d` >> $LFILE

output to $FILE, I want:

Dec 16 hkhhljljgiuygkg
Dec 16 kjhgjhgufgugugk

As of now I can only get it to grep on 'Dec', which really is not good enough.





thanks
David
 
grep `date '+%b %d'` $SFILE >> $LFILE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV

It still seems to break

As you can see, it is not able to deal with %d.


I think my way of trying to get the end results is flawed.

Any suggestions on a better way to do it?


With verbose turned on when running the script...

date +%b %d
+ grep Dec 16 /var/adm/messages
grep: can't open 16
+ date +%b %d
 
Sorry for the typo:
Code:
grep "`date '+%b %d'`" $SFILE >> $LFILE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,

worked great!!

 
ok, now im getting greedy here.

How would one set it up to query(grep) the previous day and current day.

what im attempting to do is parse through a data log and pull the info only for yesterday up to the point in time the script is ran.

EG: gather info for:

Dec 16, Dec 17 (only)


thanks a bunch

 
Have a look here:
faq822-4802

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
great worked like a charm

thanks again!!
 
I have one last question, it kind of goes with my original post.

I create a file in my script, lets say

myfile : in that file there is only two things

Dec ## EG: Dec 14 (date changes daily)

with that date I need to grep other files to pull out the relevant info.

DTE=myfile

at first I started to use:
grep `cat $DTE` $SFILE >>$YESTER

Soon after, I found out this would not be quite enough.

it works fine for strings with no spaces, but again there is a natural space, so I at a loss.

thanks again

 
im using solaris so it is not supported

thanks
 
What about this ?
grep "`cat $DTE`" $SFILE >>$YESTER

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
wow, I could of sworn I tried that, but I guess not.

that did the trick.

I appreciate it, I am done.

thanks again
 
Also, if you do find you wish to use -f, the version of grep in /usr/xpg4/bin on Solaris supports that option.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top