Say I have a shell variable $string that holds some text with several newlines, e.g.:
string="this
is
a test"
I would like to convert this string into a new string new_string where all line breaks are converted into spaces:
new_string="this is a test"
I tried:
print $string | sed 's/\n/ /g'
but it didn't work
I'm also wondering if there is a way of doing this using perl -0777 's/\n/ /g' or maybe the command tr ?
grep --null-datawhere the--null-dataoption wasn’t available. Some form ofecho $string | grep …was good enough for me.\n(new line) with space in bash