Reputation: 623
Please I need to reformat a file of 60,000 lines, and each line in this format:
22/02/2016 1234567745678900
The first sequence is a date and the next is a number string. I need to, extract both fields as input variables into a shell script, so I can use both to search log files to pull out some data. So that the date is formatted in the way the log files are dated, I need to modify the date to unix timestamp format so the whole line looks such as
2016-02-22
Please what is the proper Linux awk incantation to do this, and how does it work so I can replicate next time?
Thanks!
Upvotes: 0
Views: 236
Reputation: 10865
$ awk '{gsub("/","-"); print $1,$2,"or",$2,$1}' file
22-02-2016 1234567745678900 or 1234567745678900 22-02-2016
EDIT: for the updated question
$ echo "22/02/2016 1234567745678900" | awk '{ split($1,a,"/"); print a[3] "-" a[2] "-" a[1]}'
2016-02-22
Upvotes: 0
Reputation: 811
If you wish to change the string 22/02/2016 to 22-02-2016 in a file then you can go with VI editor.
:%s/22\/02\/2016/22-02-2016/g
It will find the string 22/02/2016 and change to 22-02-2016
Upvotes: 0