27

I have a huge text file containing this string/character <200b> that I want to delete. I tried with sed but it didn't work.

sed 's/<200b>//g' file

The character never shows when I open the file with a graphic text editor like gedit, I see it with vim.

1

4 Answers 4

32

<200b> is a Unicode for "Zero Width Space". You won't find it as a string. You can pipe the character into sed like this for removal:

sed -i "s/$(echo -ne '\u200b')//g" file
5
  • 2
    Welcome to superuser: The answer maybe correct but would be better if it was surrounded with some detail on what you have done, how to use, etc. for people that may not understand and search answers in days or years to come.
    – mic84
    May 10, 2018 at 4:52
  • there was no down vote from me
    – mic84
    May 10, 2018 at 5:06
  • Combining sed and echo -ne is even more elegant than all this answers
    – Pablo A
    Jul 18, 2019 at 22:55
  • I had to add an -E for it to work: sed -iE "s/$(echo -ne '\u200b')//g" /tmp/s Mar 6, 2020 at 17:34
  • Using sed for this type of file clean-up job lends itself to automation if used in a bash script or similar. The idea is to remove these unwanted characters from a batch of pdf files converted to plain text characters using pdftotext in Linux at the command line. Feb 19, 2023 at 3:48
32

You can also get rid of this in VIM.

%s/\%u200b// - entire file
%s/\%u200b//g - entire file, more than one occurrence on a line
1
  • This is more straightforward for a single file cleanup because you get confirmation of how many characters were substituted and how many lines were found containing the target character. I used :%s#\%u200b##g. Where I chose to use the # character as a separator instead of the more common /, only a matter of preference. Feb 19, 2023 at 3:45
1

I would recommend open this file in any Text editor and do a Find and Replace.

Find: Hold Alt and press 0 1 2 9 (this will input a zero-width character).

Replace: Leave empty.

Choose "Replace all".

4
  • 1
    Depending on how "huge" the text file is, some text editors won't work on it.
    – mpez0
    Mar 8, 2015 at 23:56
  • Hi. I already tried this but it tells me that the string is not found. The file has 5 million lines. Mar 9, 2015 at 0:01
  • You have to detect how to input the same symbol as used in this file. And then use FART or Ser tool (as your file is really huge) to find and replace. I see no other option, but it doesn't mean it's not exist. Let's see if someone will post anything more effective.
    – Mike
    Mar 9, 2015 at 0:06
  • I need to add an info. the character never shows when i open the file with a graphic text editor, i see it with vim. Mar 9, 2015 at 0:13
1

For anyone using vim and want to remove whole lines with this character, you can use the ex command g

:g/\%u200b/d

You must log in to answer this question.

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