0

我有来自 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
4

2 回答 2

1

这可能对您有用(GNU sed):

sed -r ':a;$!N;/\nhttps:/!{s/\n/ /;ta};s/\s*(\n|$)/\1/;P;D' file
于 2013-04-19T12:30:37.827 回答
0
sed 'N; /\n[0-9]/s/\n/ /; s/\n$//' foo.txt
  • 在第二行读取
  • 查找以数字开头的行,将其与上一行合并
  • 删除空行
于 2013-04-19T07:40:38.737 回答