shell


sed add line at the end of file


I trying to add a line at the end of file (/root/test.conf) with sed. I use FreeBSD and when I try to add a simple line, I always get several errors like:
extra characters at the of command
undefined label 'est.conf'
The file is like this:
#Test
firstLine
secondLine
!p.p
*.*
And I want to add something like this:
(return \n)
!word
other (5 tab between "other" and "/usr/local") /usr/local
If it's not possible with sed, there are another options?
Thank you!
It doesn't sound like you need to use sed at all, maybe just cat with a heredoc:
cat test.conf - <<EOF
whatever you want here
more stuff
EOF
The - argument causes cat to listen on standard input, which allows you to use a heredoc as well as a file.
You can add a redirect > tmp before <<EOF to output to another file called tmp.
To add literal tabs in the interactive terminal, you can use Ctrl-v followed by Tab.
You don't need any special tools like sed to add some lines to the end of files.
$ echo "This is last line" >>file
#or
$ printf "This is last line\n" >>file
works just fine in almost any platform. You might need to escape special characters though, or enclose them in single/double quotes.

Related Links

awk: “not enough arguments to satisfy format string” error in script
Arithmetic calculation causes “operator expected”
sublimetext 3 - running specific application with system build or use something else?
How to calculate complex exponential in shell script [duplicate]
Error in Bash for a Terminal based game (shell scripting)
Adding shell interpreter to zeppelin
converting multi lines of a file a file with single strings per line
Executing the >> shell operator from a Julia program
Comparing two Java versions number string and install newer one
Replace date in a parameter file with system date
Shell: script.sh is writing empty files
extract information from a file in unix using shell script
invalid condition in the if statement [duplicate]
I have to run a command in shell script and that command is asking for username and password and I want to hardcode it in script
How to install shell commands to enable the atom command at the command line?
shell command to achieve SCP task in Cloudbees

Categories

HOME
cygwin
oracle12c
telegram
google-spreadsheet
formal-languages
octave
text-mining
automatic-ref-counting
symbol
firefox-addon
vuejs
html5-appcache
asp.net-core-webapi
lilypond
pchart
apktool
handler
winexe
datastax-enterprise-graph
nsurl
recurring-events
simplecv
android-sugarorm
code-snippets
openwhisk
modalviewcontroller
apiary.io
wurfl
sim-card
kill
apache-stanbol
branching-and-merging
placeholder
procfile
nanoc
dotnet-httpclient
yii2-api
appdomain
oracleclient
boo
objectscript
branch-prediction
visual-studio-2008-sp1
pacemaker
watch-os-2
windows-azure-queues
i386
firebase-security
nss
spring-retry
sciruby
file-move
pypiserver
video-player
fuelcms
zen-cart
visual-sourcesafe-2005
xmltype
webfinger
teaspoon
entry-point
template-deduction
parallel-testing
jquery-slider
ios8-extension
dsym
spring-3
solace-mq
cnf
chart-director
resource-management
frameworkelementfactory
patricia-trie
monotouch.dialog
floating-point-exceptions
urlrewriter
cgbitmapcontextcreate
msr
photolibrary
web-garden
isapi-extension
complex-event-processing
xpsdocument
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App