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

running a date commnad with awk 1

Status
Not open for further replies.

alphaaa

Technical User
Jan 15, 2002
45
0
0
US
My question is how to run a command like date with its parameter into awk or grep commnad? I need to collect a strings contain todays date in the following format.
For example 17/Feb/2003.

-Thanks
 
[tt]man date[/tt] and [tt]date --help[/tt] should tell you how to output that. //Daniel
 
From the command line:
Code:
date +'%d/%b/%Y'
Using awk
Code:
nawk -v date=`date +&quot;%d/%b%Y&quot;` -f <awkfile> <inputfile>
Hope this helps :)
 
Here's another way to get a date variable from inside awk

BEGIN {
DT = &quot;date \&quot;+%d/%b/%Y\&quot;&quot;
DT | getline date
close( DT )
}
{
#...
}
END {
#...
} Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
man awk :
strftime([format [, timestamp]])
Formats timestamp according to the specification in format. The timestamp should be of the same form as returned by systime(). If timestamp is missing, the current time of day is used.......


so:
awk 'BEGIN{date=strftime(&quot;%d/%b/%Y&quot;);print date}'


__
___
 
'strftime' is gawk specific.

gawk != (awk|nawk) vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Now see I would put this in a small script,
Here is an example for using grep



M=`date +%b` # Set month three letter
m=`date +%m` # Set month two digits
d=`date +%d` # set Day two digits
H=`date +%H` # Set Hour two digit
Y=`date +%Y` # Set Year four digit


grep &quot;$d/$b/$Y&quot; <Filename>




Hope this helps.




 
Vgersh is on the money.
Don't assume that your awk is another mans awk.
In the wide world of *nix it doesn't work that
way ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top