I'd like to re-format a text file such that the line immediately bellow the matching string gets cut and appended to the line with the matching string. Here is an example text:
find / -name filename &
find / -name filename
bg find / -name filename
X. find / -name filename &
Y. find / -name filename
Z. bg find / -name filenames
$str =~ s/\s+$//;
It would help to see your full solution, but here's a one-liner that does what you'd like:
perl -pe's/\s*$/ / if /^.+?[:.]/'
This replaces any whitespace, including a newline, at the end of the string with a single space, but only if the pattern matches. The pattern looks for some characters at the beginning of the line followed by a period or colon. Add
-i.bak to modify files in-place. Hope this helps!