Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 07-20-2013
bartus11's Unix or Linux Image
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 28 June 2015, 6:17 PM EDT
Posts: 3,733
Thanks: 7
Thanked 1,152 Times in 1,122 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 02: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 01: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 04: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 09:03 PM
compare today's date with date in a file siog UNIX for Dummies Questions & Answers 4 10-04-2006 11:55 AM



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