Adding date when using awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Adding date when using awk
# 1  
Old 07-22-2010
Adding date when using awk

Hi,
I want to print the number of lines of a file along with filename and today's date.

Ex:
Code:
XXX|07-22-2010|8

I am using as
Code:
wc -c -l file.txt | awk '{print "XXX|",date +"%m-%d-%Y","|",$1}'

But this one prints as
Code:
AAA| 0 | 8

Can anyone please help me on this for printing the date?

Thanks,

Last edited by Franklin52; 07-22-2010 at 01:04 PM.. Reason: Please use code tags
# 2  
Old 07-22-2010
Something like this?
Code:
awk -v d=$(date +"%m-%d-%Y") 'END{print NR, FILENAME, d}' OFS="|" file

# 3  
Old 07-22-2010
Why awk?

Code:
# COUNT=`cat somefile.txt | wc -l`; echo "XXX|"`date +"%m-%d-%Y"`"|"$COUNT
XXX|07-22-2010|8

# 4  
Old 07-22-2010
Thank you...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding days to date

Hi, please can somebody let me know the easiest way to add days to a date. I can do this in perl but would like to able to do it in a shell script. Desired output would be: date +'%Y-%m-%d' + 10 = 2016-05-02 Thank you (8 Replies)
Discussion started by: andy391791
8 Replies

2. Shell Programming and Scripting

Adding one day to a date

Hi All, I want to add one day to a date and store it in a variable. From GUI we are passing value (last day of the month)to $t_date. This $t_date will give me the value like this %Y%m%d 20150531. Now I want to add one day to this value and store it in a variable "datein". datein should... (8 Replies)
Discussion started by: ROCK_PLSQL
8 Replies

3. UNIX for Advanced & Expert Users

Problem with adding date

Hi All, Please let me know the error in the below code. m=(0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) M=$(date +%m) Y=$(date +%Y) if ; then M=01 Y=$(($Y+1)) else M=$M+1)printf "01-%s-%d\n" ${m} $Y fi Log: + m=(0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) ++... (4 Replies)
Discussion started by: kiranparsha
4 Replies

4. Shell Programming and Scripting

Adding/ Subtracting from Date

Hi , How can I add/substruct x number of days with date? For example My_Date=`date` Now I need Hope it's clear. (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

5. Shell Programming and Scripting

Adding date to file

I want this: 0.0230769,0.407692,0.307692,0,0.1,1.4,1,0,ADD DATE HERE, im getting this: 11/02/12 0.00192308,0.0269231,0.0192308,0,0.1,1.4,1,0, my script: #!/bin/ksh DIR=/export/home/yani_m/scripts/scrip_out_put/ DIR2=/export/home/yani_m/scripts/scrip_out_put/calc/ Date=$1... (1 Reply)
Discussion started by: LucyYani
1 Replies

6. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

7. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

8. Shell Programming and Scripting

adding a date to the last of each file name

i have some files in my directory....wit names say aaa, bbb, ccc,,,,, i want to make loop so that for each file name,,,,,,a sysdate should be appended in the end.........and the files should look like aaa_20100331 i knw date can be appended as `date +"%Y%m%d"` but m nt able to make a loop. ... (2 Replies)
Discussion started by: amitpta
2 Replies

9. UNIX for Dummies Questions & Answers

Adding a date as a first column

I want to add a date to a record which is appended to a file that gets its data from an external source. An explanation: 1. Getting external data: curl http://www.example.com/temperatures.txt 2. Getting the required record: | grep mylocation 3. Appending to file: >> mytemperatures.txt ... (2 Replies)
Discussion started by: figaro
2 Replies

10. Shell Programming and Scripting

adding date to cron log

Hi. I'm trying to output the current date to a cronjob log file. Nothing seems to work, echo $(date), echo `date` or just date in the script. I'm using /sbin/sh Any ideas? Thanks, John (2 Replies)
Discussion started by: JohnH
2 Replies
Login or Register to Ask a Question