bash 使用 sed 在文件的第一个位置插入单词
bash insert word at first position in file using sed
如何使用 sed
在文件的起始位置的第一行插入一个单词。
例如,我有以下内容的文件:
that is a test without scope
that is the second line
that is the third line
结果应该是:
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
我正在尝试此操作,但出现以下错误:
sed -i -E "1s/^[$ISSUE_ID]/ " $COMMIT_EDITMSG_FILE
sed: -e expression #1, char 17: unterminated `s' command
我已经遵循了一些示例,但我无法取得任何进展。
你可以使用这个sed
:
sed "1s/^/$ISSUE_ID /" file
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
这里:
1s
将仅在第一行应用 s
命令
^
将匹配行开始
"..."
会让 shell 变量扩展
如何使用 sed
在文件的起始位置的第一行插入一个单词。
例如,我有以下内容的文件:
that is a test without scope
that is the second line
that is the third line
结果应该是:
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
我正在尝试此操作,但出现以下错误:
sed -i -E "1s/^[$ISSUE_ID]/ " $COMMIT_EDITMSG_FILE
sed: -e expression #1, char 17: unterminated `s' command
我已经遵循了一些示例,但我无法取得任何进展。
你可以使用这个sed
:
sed "1s/^/$ISSUE_ID /" file
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
这里:
1s
将仅在第一行应用s
命令^
将匹配行开始"..."
会让 shell 变量扩展