user2300940
user2300940

Reputation: 2385

remove special character (^@) with sed

I want to remove "^@^@^@^@^@^@^@^@^@" from my textfile. I tried the following, but it did not work:

sed -i 's/\\^@//g' myfile.txt

Upvotes: 0

Views: 96

Answers (2)

tripleee
tripleee

Reputation: 189926

sed is not generally robust against null characters. But Perl is, and tr:

tr -d '\000' <myfile.txt >newfile.txt

Some sed variants will be able to handle null bytes with the notation which works in Perl:

perl -i -pe 's/\x00//g' myfile.txt

The -i option says to replace the original file, like some sed variants also allow you to.

Upvotes: 1

choroba
choroba

Reputation: 242343

^@ is one of the ways how to display the null byte. sed (at least the GNU one) represents it as \x00:

sed 's/\x00//g'

Upvotes: 0

Related Questions