Need to add a date column (today's date) in file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Need to add a date column (today's date) in file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-20-2013
vijay_rajni vijay_rajni is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 14 October 2013, 5:15 AM EDT
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Need to add a date column (today's date) in file

Hi

I have file with number status and date1 and date1 field,

want add a column today between column date1 and date2.

file1.txt


Code:
number status  date1  date2  
=====  ====   ===      ===== 
34567 open 27/06/13 28/06/13 
45678 open 27/06/13 28/06/13 
43567 open 27/06/13 28/06/13 
24578 open 28/06/13 28/06/13 
45890 open 28/06/13 28/06/13 
43599 open 27/06/13 28/06/13 
25578 open 28/06/13 28/06/13 
51890 open 28/06/13 28/06/13


desire file


Code:
number status  date1    today     date2  
=====  ====   ===  ==         ===== 
34567 open 27/06/13   20/7/13      28/06/13 
45678 open 27/06/13   20/7/13      28/06/13 
43567 open 27/06/13   20/7/13      28/06/13 
24578 open 28/06/13   20/7/13      28/06/13 
45890 open 28/06/13   20/7/13      28/06/13 
43599 open 27/06/13   20/7/13      28/06/13 
25578 open 28/06/13   20/7/13      28/06/13 
51890 open 28/06/13   20/7/13      28/06/13

Sponsored Links
    #2  
Old 07-20-2013
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 19 December 2014, 7:45 PM EST
Posts: 3,720
Thanks: 7
Thanked 1,147 Times in 1,118 Posts
Try:
Code:
awk 'BEGIN{"date +%d/%m/%y"|getline d}NR==1{$3=$3" today"}NR==2{$3=$3" =="}NR>2{$3=$3" "d}1' file

The Following User Says Thank You to bartus11 For This Useful Post:
vijay_rajni (07-20-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX date fuction - how to deduct days from today's date juzz4fun Shell Programming and Scripting 4 05-23-2013 03:31 PM
[Solved] Replace yesterday date with today's date except from the first line Lilu_CK Shell Programming and Scripting 3 12-03-2012 02:44 PM
Trying to add currrent date as the first the first column in the file ajaypatil_am Emergency UNIX and Linux Support 3 04-25-2012 05:48 AM
Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete citizencro UNIX for Dummies Questions & Answers 3 04-11-2011 10:03 PM
compare today's date with date in a file siog UNIX for Dummies Questions & Answers 4 10-04-2006 12:55 PM



All times are GMT -4. The time now is 04:38 AM.