Replace with last date update


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace with last date update
# 1  
Old 09-25-2014
Replace with last date update

Dear Masters,

I have file input
Code:
20140901|Cross Nation|Asia
20140908|Cross Region|Europe
20140905|Cross Nation|Europe

I want to replace column 1 with the last date update, so my output should be like
Code:
20140908|Cross Nation|Asia
20140908|Cross Region|Europe
20140908|Cross Nation|Europe

big thanks
# 2  
Old 09-25-2014
What have you tried?
# 3  
Old 09-25-2014
Code:
sort -k1,1rn file > a.txt
date ='head -n1 a.txt | awk -F'|' '{print$1}
awk -F'|' -V date=$date '{print date "|"$2$3}' a.txt

any shortest?
# 4  
Old 09-25-2014
Ok you tried something... try this

Code:
$ awk 'FNR==NR{if($1 > m) m = $1 ; next}{$1 = m}1' FS='|' OFS='|' file file

This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 09-25-2014
superbe...
can you explain why there is no sort function in your code but the result is still ok as expected?
# 6  
Old 09-25-2014
I calculated max date first and then substituted to field1, as you can see I am reading file twice.
This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 09-25-2014
big thanks bro!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

3. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

4. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

5. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

6. Shell Programming and Scripting

Replace date on a line with current date

Hi Guys, I have a file with following content From 20121014 : To 20121014 Number of days : 1 1234 1245 1246 1111 Everyday i run my script i want to modify "To" date on the first line with current date. I have set the current date in script as RUN_DATE=`date -u +%Y%m%d` So i want... (9 Replies)
Discussion started by: jakSun8
9 Replies

7. Shell Programming and Scripting

Searching for unknown date inside the file and replace to new date

Hello, Iam a newbies to Shell scripting. Iam trying to replace the date inside the file to new date. is there anyway that we can just use the pattern to search as "..." I have many files want to replace with the same date, and each file contains different date. Thanks for your help. ... (2 Replies)
Discussion started by: Daro
2 Replies

8. Shell Programming and Scripting

how to update date part with new increment date time

hi experts, my requirement is like this i need to develop a shell script to update date part with new incremental date time in file some 'X' which is kept at some server location incrementing every two hours.as i am new to this scripting i need support from u people,thanx in advance (1 Reply)
Discussion started by: amanmro
1 Replies

9. Shell Programming and Scripting

Search Replace and Update a file

hi, I am stuck at a place. Please help me out. Here is what i need to do. Search for a pattern in a propertyfile and change only at one occurance. I have these statements and assignment as a part of the propertyfile #Note : The Address should be replaced with actual address dynamically. ... (7 Replies)
Discussion started by: raghu_shekar
7 Replies

10. Shell Programming and Scripting

replace old date in scripts with new date

Hiee .... i want an immediate solution for this.... Let replace.cfg file contains a list of files to be replaced the old dates with new dates...... The script must take 3 parameters.... 1) old date 2) new date 3) .config file Can u get me the solution...... I tried with sed but i... (2 Replies)
Discussion started by: prasanna1983
2 Replies
Login or Register to Ask a Question