sed命令用于美化awk命令的输出

时间:2013-04-19 07:34:14

标签: sed awk cut

我有一个awk命令的以下输出..我想美化输出如下..是否有一个sed命令将给我预期的输出?

CURRENT OUTPUT:-
    https://code-comp.com/308271
                                (there is white space line here)   
    https://code-comp.com/308270
    466197
    https://code-comp.com/308263
    470188
    https://code-comp.com/308262
    https://code-comp.com/308261

以下是预期的输出

    EXPECTED OUTPUT:-
    https://code-comp.com/308271
    https://code-comp.com/308270 466197
    https://code-comp.com/308263 470188
    https://code-comp.com/308262
    https://code-comp.com/308261

2 个答案:

答案 0 :(得分:1)

这可能适合你(GNU sed):

sed -r ':a;$!N;/\nhttps:/!{s/\n/ /;ta};s/\s*(\n|$)/\1/;P;D' file

答案 1 :(得分:0)

sed 'N; /\n[0-9]/s/\n/ /; s/\n$//' foo.txt
  • 在第二行阅读
  • 查找以数字开头的行,合并前一行的行
  • 删除空行