Issue
How can I use sed
to insert a word at the first line of a file at start position.
For instance I have the file witn the following content:
that is a test without scope
that is the second line
that is the third line
The result should be:
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
I'm trying this, but I get the following error:
sed -i -E "1s/^[$ISSUE_ID]/ " $COMMIT_EDITMSG_FILE
sed: -e expression #1, char 17: unterminated `s' command
I've followed some examples, but I can not make any progress.
Solution
You may use this sed
:
sed "1s/^/$ISSUE_ID /" file
[TICKET_NUMBER] that is a test without scope
that is the second line
that is the third line
Here:
1s
will applys
command on first line only^
will match line start"..."
will let shell variable expand
Answered By - anubhava Answer Checked By - Candace Johnson (WPSolving Volunteer)