user3354635
user3354635

Reputation: 9

Changing date format in a file with multiple records and columns

I am fairly new to awk, and I am having a file with four columns, separated by a space and I would like to change the date format of the 2nd and third column. I have shared a sample of the record below

349287741 20140123 20140329 7

I would like to change the date from %Y%m%d to %Y-%m-%d without affecting the record positions.

Upvotes: 0

Views: 48

Answers (1)

sat
sat

Reputation: 14949

You can try this awk,

awk '{ "date -d "$2" +%Y-%m-%d"|getline $2; "date -d "$3" +%Y-%m-%d"|getline $3;}1' yourfile

Upvotes: 1

Related Questions