V Sri Sandeep
V Sri Sandeep

Reputation: 15

Replacing a character between numbers in UNIX

I have a file in UNIX which has a character in the time stamp

2016-06-24T14:00:00.1000000;True; 

I want to replace the T in the time stamp with blank. I used sed but it didn't work.

sed -i.bak 's/[0-9]T[0-9]/ /g' filename.csv

When I run the script it is converting the output to:

2016-06-2 4:00:00.1000000;True;

It's lost the 4 before the T and the 1 after it.

Upvotes: 0

Views: 79

Answers (2)

Matías W.
Matías W.

Reputation: 350

Use tr with pipe:

cat filename.csv |  tr 'T' ''

Upvotes: -1

sat
sat

Reputation: 14949

You need to capture digits before and after T. Then, you do not need g (global substitution).

sed 's/\([0-9]\)T\([0-9]\)/\1 \2/' file

Upvotes: 2

Related Questions