How to search for a character the displays as "<85>" in Vim
Asked Answered
M

3

19

I have a file that was converted from EBCDIC to ASCII. Where there used to be new lines there are now characters that show up as <85> (a symbol representing a single character, not the four characters it appears to be) and the whole file is on one line. I want to search for them and replace them all with new lines again, but I don't know how.

I tried putting the cursor over one and using * to search for the next occurrence, hoping that it might show up in my / search history. That didn't work, it just searched for the word that followed the <85> character.

I searched Google, but didn't see anything obvious.

My goal is to build a search and replace string like:

:%s/<85>/\n/g   

Which currently just gives me:

E486: Pattern not found: <85>  
Mannes answered 18/1, 2010 at 15:57 Comment(1)
You can press y<Space> to copy a single character.Northing
T
26

I found "Find & Replace non-printable characters in vim" searching Google. It seems like you should be able to do:

:%s/\%x85/\r/gc

Omit the c to do the replacement without prompting, try with c first to make sure it is doing what you want it to do.

In Vim, typing :h \%x gives more details. In addition to \%x, you can use \%d, \%o, \%u and \%U for decimal, octal, up to four and up to eight hexadecimal characters.

Tiffany answered 18/1, 2010 at 16:21 Comment(0)
P
2

For special character searching, win1252 for example, for the case of <80>,<90>,<9d>... type:

/\%u80, \/%u90, /\%u9d ...

from the editor.

Similarly for octal, decimal, hex, type: /\%oYourCode, /\%dYourCode, /\%xYourCode.

Pascasia answered 23/4, 2020 at 16:36 Comment(0)
F
-4

try this: :%s/<85>/^M/g

note: press Ctrl-V together then M

or if you don't mind using another tool,

awk '{gsub("<85>","\n")}1' file
Fibered answered 18/1, 2010 at 16:0 Comment(3)
The \n isn't the problem. It's the <85>. Thanks though.Mannes
The "<85>" is a single character, not a four character string of <, 8, 5, and >.Mannes
echo '------------------------------------------------------------------------- BEGIN ----------------------------------------------------------------------- '<85>binDir=...etc, etc...Mannes

© 2022 - 2024 — McMap. All rights reserved.