echo -e " fu bar\n foo \n\n bar \n\n\n baz "
fu bar foo bar baz
2018-02-27T15:08:56 LinuxerErstmal wäre zu klären, was genau Du machen willst?
... | tr '\n' ' ' | sed -E 's/^\s+|\s+$//g'
fuu bar baz
echo -e " fu bar\n foo \n\n bar \n\n\n baz " | perl -nE 's/^\s+//; s/\s+$/ /; $new .= $_; END{ $new =~ s/\s+$//; say ">$new<"; }'
>fu bar foo bar baz<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /bin/bash
# helper script simulator
VAR=" fu bar\n foo \n\n bar \n\n\n baz "
echo -e "$VAR" | perl -nE '
# this code is used inside a loop because of -n option
s/^\s+//; # remove leading whitespaces from lines
s/\s+$/ /; # replace trailing whitespaces (including newlines) with a single whitespace
$output .= $_; # append to a variable for later output
# at the end, do this
END {
$output =~ s/\s+$//; # remove trailing whitespace
say qq~>$output<~; # testing output
#say $output; # production output
}
' #END_OF_PERL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /bin/bash
# helper script simulator
VAR=" fu bar\n foo \n\n bar \n\n\n baz "
make_single_line() {
perl -nE '
# this code is used inside a loop because of -n option
s/^\s+//; # remove leading whitespaces from lines
s/\s+$/ /; # replace trailing whitespaces (including newlines) with a single whitespace
$output .= $_; # append to a variable for later output
# at the end, do this
END {
$output =~ s/\s+$//; # remove trailing whitespace
say qq~>$output<~; # testing output
#say $output; # production output
}
' #END_OF_PERL
}
echo -e "$VAR" | make_single_line | vim -