How can I remove nanosecond from every line in a file. data looks like filename is test.csv
ip,time,name
1.1.1.1,2018-08-17 15:05:52:016469121,1.13.0-0007
1.1.1.2,2018-08-17 15:05:52:016469121,1.13.0-0007
Try
sed 's/:[[:digit:]]*,/,/' file
ip,time,name
1.1.1.1,2018-08-17 15:05:52,1.13.0-0007
1.1.1.2,2018-08-17 15:05:52,1.13.0-0007
it will replace the last colon, following digits, and final comma with just the comma.
awk -F',' -vOFS=',' '{sub(/:[0-9]{9}$/, "", $2); print}' input.txt
Output:
ip,time,name
1.1.1.1 2018-08-17 15:05:52 1.13.0-0007
1.1.1.2 2018-08-17 15:05:52 1.13.0-0007
awk -F',' -vOFS=',' '{foo}' input.txt: use awk with the field separator (and output field separator) ,, running commands foo, on file input.txt.sub(/:[0-9]{9}$/, "", $2);: for the second field $2, replace the regular expression :[0-9]{9}$ (i.e. nine digits in a row at the end of the field) with nothing.print: print the new line