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

using variables and sed to find double spaced dates

Status
Not open for further replies.

edwardb15

Technical User
Mar 23, 2004
10
AU
hi,
i am trying to use sed to replace a single space in a date variable with a double space and then use that value to find all entries in a log file:

num_day="8"
C_HOUR="13"
C_DATE='Wed Dec 8'
C_DATE="`echo $C_DATE | /bin/sed -e 's/'${num_day}'/ '${num_day}'/'`"
# replaces day number with double spaces i.e.Wed Dec 8 with # Wed Dec 8

# write all lines beginning from ${C_DATE} in
# alert_TEST.log to errors.dat file
sed -n "/^${C_DATE} $C_HOUR.*1999/,$ p" alert_TEST.log > errors.dat

the variable C_DATE used outside of " " removes multiple spaces.

any help would be very much appreciated.
thanks.
ed.
 
[tt]
awk -v d="${C_DATE} $C_HOUR" -v y=1999 '
BEGIN{$0=d; $3=sprintf("%2d",$3); d=$0}
$0 ~ d ".*" y, 0
' alert_TEST.log > errors.dat
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top