Cripto
Cripto

Reputation: 3751

Shell script replacing string with a little logic

I have files that in-correctly contain

``` Some text ```

and I need to replace the ticks to pre

<pre> Some text </pre>

The trick is, the first pre doest have / but the seccond pre does.

Upvotes: 0

Views: 40

Answers (1)

jaypal singh
jaypal singh

Reputation: 77155

Using GNU awk:

$ cat file
``` Some text ```
``` Some
text ```
$ gawk -v RS='```' -v ORS= 'NR>1{$0=(!(NR%2)?"<pre>":"</pre>")$0}1' file
<pre> Some text </pre>
<pre> Some
text </pre>

Upvotes: 2

Related Questions