Using sed command to replace newlines

WordPress is always modificating their software to improve speed and try to bring good things to users. Unfortunately the Block editor is not a good these things, at least not for me.

Recently while editing my post about my list of musics ( https://acassis.wordpress.com/2008/10/22/msicas-mais-ouvidas/ ) it placed the new lines between Music (Musica) and Artist (Cantor).

Then it became:

Music: Blablabla

Artist: Blabla

Music: Blablabla2

Artist: Blabla2

I wanted to restore the old organization:

Music: Blablabla
Artist: Blabla

Music: Blablabla2
Artist: Blabla2

Instead editing it be hand I tried to use VIM text editor, but vim recognizes \n as \0. And although there are some other ways to get it working on vim, Ctrl+J etc didn’t work as expected.

Then I remembered that sed -i could do the trick:

I tested this idea:

sed -i 's/\n\nCantor/\nCantor/g' musics.txt

It didn’t work, then searching in the Internet I found this post:
http://www.benjiegillam.com/2011/09/using-sed-to-replace-newlines/

Then the command became:

sed -i ':a;N;$!ba;s/\n\nCantor/\nCantor/g' musicas.txt

Now the order was restored.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s