awk to print current date?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk to print current date?
# 1  
Old 09-02-2008
awk to print current date?

List,

I want to print the first line of my text file (say "me you"), preceded by the current date/time.

Something like (pseudo code):
awk '{print date,$1}'

I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious...
# 2  
Old 09-02-2008
Something like:

Code:
awk 'NR==1{print d, $1}{ ... }' "d=$(date)" file

# 3  
Old 09-02-2008
This worked:

awk '{print d, $1}' "d=$(date)" test.txt

Not sure why you added the { ... }

Thanks a lot!
# 4  
Old 09-02-2008
Quote:
Originally Posted by philipz
Not sure why you added the { ... }
Thanks a lot!
I assume you have more then one command?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Find and print specific date with awk

hi all I would like to help me find the problem with this script to find and print to the screen a specific date of a log file that I have on my server, the date it is received as the first argument in the script $ 1 Here I show you a few lines that made ​​the idea of ​​my log file: ****... (4 Replies)
Discussion started by: gilmore666
4 Replies

3. Shell Programming and Scripting

csv file field needs to be changed current system date with awk

HI, I have csv file with records as shown below. 4102,Bangalore,G10,21,08/17/2011 09:28:33:188,99,08/17/2011 09:27:33:881,08/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

4. UNIX for Dummies Questions & Answers

Awk to print data from current and previous line

Hi guys, I have found your forum super useful. However, right now I am stuck on a seemingly "simple" thing in AWK. I have two columns of data, the first column in Age (in million years) and the second column is Convergence Rate (in mm/yr). I am trying to process my data so I can use it to... (2 Replies)
Discussion started by: awk_noob_456
2 Replies

5. Shell Programming and Scripting

using awk to print date

i want to use awk to print the first,second and add date as third column in a file awk -F"|" ' { print $1,$2,current date }' tom.unl >> top.txt how can i achieve this,i need the comma's to seperate them and finally print current date and time as the third. i want output like... (5 Replies)
Discussion started by: tomjones
5 Replies

6. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

7. UNIX and Linux Applications

Print date at END clause of AWK

Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja. My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a... (4 Replies)
Discussion started by: fmeriles
4 Replies

8. UNIX for Dummies Questions & Answers

print all dates 100 days from current date

can anyone please suggest me on ideas to write a script which has to go back to 100 days from 'current date' and print the date of each day starting from 100th day to current day. (korn shell please) Thanks Pavan (5 Replies)
Discussion started by: pavan_test
5 Replies

9. Shell Programming and Scripting

Using awk and current date command

I am running a command to extract data from a database which has different text and dates (ex. 01/03/07, 05/29/08, 06/05/08). Once the file is created I need to grep for all the text with a current date then redirect the sorted data to another file then email the file out. Here is what I have right... (2 Replies)
Discussion started by: wereyou
2 Replies

10. Programming

may be simple but i don't know -- Print current date from C program

How to print current date of the Unix system accessing thru C++ program ? I wrote like this #include <time.h> ....... time_t tt; struct tm *tod; .... time(&tt); tod = localtime(&tt); cout << tod->tm_mon + 1 << "/" << tod->tm_mday << "/" ... (6 Replies)
Discussion started by: ls1429
6 Replies
Login or Register to Ask a Question