标签:
cat text
1
2
11
22
111
222
$sed ‘/1/{H;$!d};$p;$x‘ text
2
22
222
1
11
111
$sed ‘/2/{H;$!d};$x‘ text
1
11
111
2
22
222
$sed ‘H;$!d;${x;s/^\n//;s/\n/,/g}‘ text
1,2,11,22,111,222
$function join_lines()
> {
> sed ‘H;$!d;${x;s/^\n//;s/\n/,/g}‘ $1
> }
$join_lines text
1,2,11,22,111,222
$
function
join_lines()
> {
>
local
delim=${1:-,}
>
sed
‘H;$!d;${x;s/^n//;s/n/‘
$delim
‘/g}‘
> }
$
cat
text | join_lines
‘;‘
1;11;2;11;22;111;222
$
function
join_lines()
> {
>
local
delim=${1:-,}
>
sed
‘H;$!d;${x;s/^n//;s/n/‘
$delim
‘/g}‘
> }
$
cat
text | join_lines
‘&‘
1&11&2&11&22&111&222
标签:
原文地址:http://www.cnblogs.com/fanyl5/p/4795640.html