首页 > 解决方案 > bash SED命令解释带分号

问题描述

这个 sed 命令在做什么?是否有任何在线实用程序可以稍微解释一下 sed,例如正则表达式?

sed -i '1s/$/|,a Type,b Type,c Type/;/./!b;1!s/$/|,,,/' textflile.txt

我认为一开始它是在行尾添加 csv a type, b type, c type 但命令的其余部分也是什么

标签: sed

解决方案


我不知道任何此类实用程序,但让我使用文本编辑器进行解释:

sed -i '1s/$/|,a Type,b Type,c Type/;/./!b;1!s/$/|,,,/' textflile.txt
    ^   ^  ^                          ^ ^^ ^^                       ^
    |   |  |                          | || ||                       |
modify  |  End                Non-empty || ||                       input
the     |  of                 lines     || |Negation,               file
file    |  line               only      || |i.e. lines 2,3,...
in      |                               || |
place   |                               || First
     First line            Negation, i.e.| line
                         empty lines only|
                                         Branch to
                                         script end,
                                         i.e. skip the rest

换句话说,它添加|,a type, b Type,c Type到第一行,不更改空行,并添加|,,,到所有剩余的行。


推荐阅读