Im trying to insert a line containing these characters: ~o to the beginning of a file. Im using: sed -i '' "1s/^/~o \n/" macros But the newline option just doesn't do its job. How should I change it ? Thank you
You can use the insert command i:
sed '1i\TEXT TO INSERT' file
Explanation:
1 Addresses the first line
i The insert command inserts the following
text before(!) line 1
\ Required after i (in POSIX compatible versions of sed)
TEXT The text to insert
Example:
sed '1i\Hello' <<< 'world!'
Output:
Hello
world!
Btw, i works even with newline characters:
sed '1i\Hello\n' <<< 'world'
Output:
Hello
world!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With