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

piping to variables
shell script to quickly jump to a directory
adding or changing variable value
understanding a ksh script part of
cakephp: using l10n in cake console
shell script execution error in uclinux
How can I shuffle the lines of a text file on the Unix command line or in a shell script?
csh different from bash when expend *NAME* patten to file name list
pass arguments between shell scripts but retain quotes
Running matlab in the background
Shell Script + Write to File a String
Using logical OR (||) in C-Shell
bourne shell single-quote, doublequote & backquote question
Iterate through XML with xmlstarlet
Replacing all GUIDs in a file with new GUIDs from the command line
Write shell script that can only be run by a sudo user in Ubuntu

Categories

HOME
beautifulsoup
design-patterns
checkstyle
fpga
solver
can
appcelerator
tivoli
nsbundle
iis-6
nstableheaderview
accessibility
g++
vimdiff
openpyxl
jxl
rtf
nancy
plink
foreign-keys
drive
springfox
dpdk
qliksense
monit
resourcebundle
itunes
surveymonkey
outliers
aws-codecommit
jbutton
quickfixj
playstation-portable
linkedhashmap
dynamic-jasper
fossil
sharding
least-squares
mnist
imx6
parse-tree
xcode7.3
flatmap
nohup
bc
loading
urlsession
preloader
glm-math
http-request
placeholder
strftime
nanoc
ovf
openal
sonarlint-eclipse
globalize
tinymce-3
twilio-click-to-call
insight
video-conferencing
subnet
mach-o
rocks
simplepie
lrs
windows-azure-queues
model-associations
kendo-upload
boomerang
flock
ons-api
toolkit
doctype
evolus-pencil
sql-server-data-tools
linked-tables
google-refine
jquery-forms-plugin
infosphere-spl
boost-program-options
rmysql
mobility
drupal-nodes
cnf
nebula
diem
actiondispatch
zope.interface
os.system
role
android-holo-everywhere
google-ajax-api
pylucene
scrollbars
lobo-cobra
entitykey
soappy
online-storage

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App