Thursday, April 28, 2022

[SOLVED] UNIX: using tr to delete empty lines

Issue

I've seen it being done using sed (if you'd be so kind to write how to do it in sed and explain the regex behind it, I will appreciate it too), but I'd like to know how to do it using tr.

My idea was: cat file|tr -d ^'\n' or ^\n, but the first one deleted every '\n', the second one none.


Solution

tr on linux, at least, can squeeze repeated characters:

echo -ne $a
the quick
brown fox

jumps over
echo -ne $a |tr -s '\n'
the quick
brown fox
jumps over


Answered By - stark
Answer Checked By - David Marino (WPSolving Volunteer)