SriniDK
SriniDK

Reputation: 79

awk append in CSV file

How to use awk command, as I need to add or append a 000 to my below timestamp column. I try to use the below command,

head -n 10000001 ratings.csv | tail -n +2 | awk '{print $1 "000"}' >> ratings_1.csv

but data is not as expected.

$ cat ratings.csv |wc -l
20000264
$ head ratings.csv
userId,movieId,rating,timestamp
1,2,3.5,1112486027
1,29,3.5,1112484676
1,32,3.5,1112484819
1,47,3.5,1112484727
1,50,3.5,1112484580
1,112,3.5,1094785740
1,151,4.0,1094785734
1,223,4.0,1112485573
1,253,4.0,1112484940

My expected output should look like

1,2,3.5,1112486027000

Upvotes: 0

Views: 334

Answers (1)

Ricardo Branco
Ricardo Branco

Reputation: 6079

awk '{ if (NR > 1) { $1 = $1 "000" } print }'

Maybe a faster version that wouldn't run the if on every line would be:

awk 'BEGIN { getline; print } { print $0 "000" }'

Upvotes: 1

Related Questions