Stripping out newlines from string

Problem

Different versions of UNIX handle the stripping of newlines in a string differently. Obviously if you echo a string, the shell automatically expands newlines “n”.



Solution

sed and tr don’t appear to like performing these substitutions. But with Perl its a steal. 🙂



Example



% echo 'hello worldnhello worldntest it' | perl -ane 's#\n# #g; print,"";'

hello world hello world test it



Reference

[tags], Unix Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *