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!

AWK script - How to add a date format column 1

Status
Not open for further replies.

umi6kg

MIS
Jan 6, 2003
3
JP
I'm very new to AWK, and not good at English.
It must be easy though I haven't solved it yet.

What I want to do is to add a column which is date,
now in %Y%m%d format. ex; 2003/01/07

$cat test.dat
a,b,c,100
a,c,e,100
b,a,c,100


a,b,c,100,2003/01/07
a,c,e,100,2003/01/07
b,a,c,100,2003/01/07

I want to save this file to 'new.dat'.

How can I code in 'adddate.awk'?

awk -f adddate.awk test.dat > new.dat


Could someone help me?

Thanks,
Suzy


 
Here's one way. The script adddate.awk ...
Code:
# nawk script : adddate.awk

BEGIN {
IFS=","
OFS=","
}

{print $0,dt}
Run from the command line using ...

nawk -v dt=`date +%Y/%m/%d` -f adddate.awk test.dat > new.dat

Greg.
 
Or...

BEGIN {"date +'%Y/%m/%d'" | getline dt}
{print $0 "," dt}
CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top