0

There is a csv file

ip,time,name
1.1.1.1,2018-08-31 10:01:03,postgres
2.1.1.1,2018-08-31 12:51:13,oracle
3.1.1.1,2018-08-31 14:32:53,sql

I need output as below

ip,time,name
1.1.1.1,2018-08-31 10:01:03.1,postgres
2.1.1.1,2018-08-31 12:51:13.1,oracle
3.1.1.1,2018-08-31 14:32:53.1,sql

2 Answers 2

2

Use this:

awk -F, 'BEGIN{OFS=","} NR>1{$2=$2".1"}1' file
  • -F, sets the input field separator
  • BEGIN{OFS=","} sets the output field separator
  • NR>1{$2=$2".1"} appends a .1 if the line number is greater than 0 to the second field
0
1

Using sed:

$ sed '2,$s/,/.1,/2' file
ip,time,name
1.1.1.1,2018-08-31 10:01:03.1,postgres
2.1.1.1,2018-08-31 12:51:13.1,oracle
3.1.1.1,2018-08-31 14:32:53.1,sql

This applies a substitution to line 2 and onwards (2,$). The substitution s/,/.1,/2 replaces the second comma with .1,. It's the /2 at the end of the substitution command that makes it skip to the second match.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .