范云龙

博客园 首页 联系 订阅 管理

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

 


 

posted on 2015-09-09 19:11  范云龙  阅读(151)  评论(0编辑  收藏  举报