Reputation: 3
I need to add a new line to the end of a file. But when I am running sed command on MacOS I get an error.
The command I run
sed -i'' -e '$a\wrapper{gradleVersion='5.5'}' build.gradle
The error I get:
sed: 1: "$a\wrapper{gradleVersio ...": extra characters after \ at the end of a command
Upvotes: 0
Views: 151
Reputation: 5006
Simplest answer : do not use sed
echo "wrapper{gradleVersion='5.5'}" >> build.gradle
Pretty straightforward right ?
If you want to ignore my advices and keep using sed
, to complete @shellter comment :
On MacOS sed, you need to add newlines before the text you want to add when using a
command.
MacOS sed will not add a newline by default after the text you want to add, and because you want the file remains POSIX standard, you'll need to add it
You can do :
sed -i '' -e '$a\
<text to add>
' <file>
$
and \
which make it particularly annoying to use.Try this :
sed -i '' "\$a\\
wrapper{gradleVersion='5.5'}
" build.gradle
On gnu-sed (install it with brew brew install gnu-sed
), you would do :
gsed -i "\$a wrapper{gradleVersion='5.5'}" build.gradle
Upvotes: 3