Abhishek Sharma
Abhishek Sharma

Reputation: 619

remove repeated string character from every line in a file in Unix

I have a file in Unix that has a '\' character at the end of every line. I would like to remove it from every line. There are over 1000 lines.

I have seen some examples, but didn't quite work. I am new to Unix and hoping I would get my answer here.

Thanks,

Ab

Upvotes: 0

Views: 479

Answers (3)

squiguy
squiguy

Reputation: 33370

A Perl one-liner.

perl -i~ -pe 's/\\$//' file

This will create a backup of the original with a ~ extension and replace every \ at the end of each line.

Upvotes: 0

divinediu
divinediu

Reputation: 433

This eliminates the last character of e sed 's/.$//' original_file > new_file

Upvotes: 0

Gilles Quénot
Gilles Quénot

Reputation: 185219

Try doing this :

sed -i.~ 's@\\$@@g' file.txt

EXPLANATIONS

  • -i do the substitution for real in the file
  • .~ makes backup files with this suffix
  • s@@@ is the skeleton syntax for substitutions (I have arbitrary chosen @ as delimiter)
  • $ mean end of line

Upvotes: 1

Related Questions