How can you combine all lines that end with a backslash character?
a shorter and simpler sed solution:
sed '
: again
/\\$/ {
N
s/\\\n//
t again
}
' textfile
or one-liner if using GNU sed
:
sed ':x; /\\$/ { N; s/\\\n//; tx }' textfile
Here's an awk solution. If a line ends with a \
, strip the backslash and print the line with no terminating newline; otherwise print the line with a terminating newline.
awk '{if (sub(/\\$/,"")) printf "%s", $0; else print $0}'
It's also not too bad in sed, though awk is obviously more readable.
It is possibly easiest with perl (since perl is like sed and awk, I hope it is acceptable to you):
perl -p -e 's/\\\n//'