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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble using egrep to return information... 1

Status
Not open for further replies.

chanman525

IS-IT--Management
Oct 7, 2003
169
US
Hey all. I think my eyes are playing tricks on me. I can't seem to figure out how to get this grep to work. Basically I want to get information out of a lot file from today and yesterday and place it in it's own seperate log file. I got my "yesterday's date" calculation done, but the log file where I am placing my information is now showing the previous day. Here are the lines of code I am dealing with...

STARTSHIFT="$LASTMONTH|$LASTDAY|$LASTYEAR"

cat $SUPPORT |grep "$Fdate" > $LOG/support.log
cat $SUPPORT | egrep "$STARTSHIFT >> /$LOG/support.log

Fdate is today's date
Last Month = March
Last day = 19
Last year = 2007.

The log file is shown in a standard "date" format.

Tue Mar 19 15:11:10 EDT 2007

Am I missing something here?
 
Your grep RE needs to be altered. Right now you're grepping for lines that contain either the string "Mar" (yesterday's month), "19" (yesterday's date), or 2007 (yesterday's year).

I'd grep for something like
"${LASTMONTH} ${LASTDAY} .* ${LASTYEAR}"

Code:
...
STARTSHIFT="${LASTMONTH} ${LASTDAY} .* ${LASTYEAR}"

grep "${Fdate}" ${SUPPORT} > $LOG/support.log
egrep "${STARTSHIFT}" ${SUPPORT} >> /$LOG/support.log
...

Also in your post, you omitted a closing dblquote char. And there's no need to cat, grep/egrep can open the log file just as good...


HTH,

p5wizard
 
That did it p5. Appreciate the help.

Also, I didn't think that you had to cat the file. Still learning and it's people like you and Rod that really help me out. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top