skip to Main Content

I have a txt file under CentOS in which I want to replace any "tn" with "tt". I tried this:

sed -i -E 's/tn/tt/g' myfile.txt

but it doesn’t work. I don’t know if CentOS doesn’t support regex in sed.

Any help is appreciated!

p.s.

Input(two lines):

1t2t3t$
4t5t6t$

Output(one line):
1t2t3tt4t5t6tt

In Editplus, the find regex is ‘tn’ and the replace is ‘tt’. Then all lines ending with ‘tn’ will become one line, and each ‘n’ is replaced by one additional ‘t’.

p.s.

my file is read like this (cat -A myfile.txt)

enter image description here


2

Answers


  1. You may use this perl command to join lines if previous line has a single tab:

    perl -i -0777 -pe 's/(St)n(?!z)/$1t/g' excel.log
    

    (?!z) is a negative lookahead to fail this match for last line of the file.

    Login or Signup to reply.
  2. You need to escape the backslashes.

    sed -i -E  's/\t\n/\t\t/g' myfile.txt
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search