user3063678
user3063678

Reputation: 13

Vim line replace that contains word

I have a text that its wrong encoded, I need to replace all the lines where:

"<96> DASH <96>" appears

And change that line to "- DASH -"

<96>    DASH    <96>
¡Bah    NC  unknown
!   FS  !
<96>    DASH    <96>
exclamó VLfin   exclamar
Olaf    NP  unknown
<96>    DASH    <96>
.   FS  .
Ahora   ADV ahora

The three elements must be separated by tabs and a CR at the end

-   DASH    -
¡Bah    NC  unknown
!   FS  !
-   DASH    -
exclamó VLfin   exclamar
Olaf    NP  unknown
-   DASH    -
.   FS  .
Ahora   ADV ahora

Any advice?

Upvotes: 0

Views: 66

Answers (2)

yolenoyer
yolenoyer

Reputation: 9445

Try this:

:%s/\%x96\s*DASH\s*\%x96/-\tDASH\t-/

The most important thing above is that \%x.. lets you search for an hexadecimal char code. The rest of the command may be modified to better fit your needs.

See :h /\%x

Upvotes: 2

Rafael Monteiro
Rafael Monteiro

Reputation: 4549

Perhaps this:

:%s/<96>\tDASH\t<96>\n/-\tDASH\t-\r/g 

Upvotes: 1

Related Questions