简体   繁体   中英

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
awk '{ if (NR > 1) { $1 = $1 "000" } print }'

也许不会在每行上运行if的更快版本是:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM