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

/dev/random is not working
shell: write integer division result to a variable and print floating number
Using awk with ssh
Select lines between known line and line with first-matched sign at the end
Index of nth occurrence of a character in a given string in UNIX
how to locate the shell script file of a process
cakephp 1.3 shell not getting associated models
shell script: Read a particular string from file
rpm unistall package error in linux
string editing in shell script
how to read a variable from a file to a Unix script in Unix
About Finding Size in Shell Script
Shell script if variable equals false? Solaris
find with grep not working inside shell script
gettting user input - shell programming
Open a new terminal and ssh to a remote machine

Categories

HOME
sonarqube
gdb
time-complexity
ggplot2
nvd3.js
dns
jelastic
socket.io
solver
shiro
error-handling
rendering
pdfbox
google-cloud-functions
dojo
gembox-spreadsheet
crystal-reports-2013
missing-data
angularfire2
joomla3.0
openstreetmap
cmdb
jxl
rtf
package-managers
coin3d
glyphicons
scsi
forgot-password
simpleitk
libigl
string-concatenation
roslyn
displaytag
direct3d11
mount
stackexchange
outliers
entity-relationship-model
firebase-analytics
wcag
sinch
livelink
postback
mockjax
gnat-gps
arduino-ide
google-knowledge-graph
ods
verifiable-c
diacritics
linq-to-objects
chef-solo
news
signals-slots
datacachefactory
glm-math
plan-9
double-click
builder
insight
dt
visual-studio-2008-sp1
grails-plugin
appscale
freepbx
gcloud-ruby
boost-serialization
createprocess
cortex-m
beanstalk
state-restoration
dynamics-nav-2016
gocql
viola-jones
liquid-layout
alloy-ui
matlab-deployment
fits
dot.js
broadband
cross-join
exceldatareader
mass-assignment
document-repository
ssis-data-flow
metatrader5
dot42
renderer
cfcache
embedded-fonts
kendo-dataviz
breakout
away3d
intersect
android-loadermanager
qtconcurrent
adobe-media-server
database-create
entity-attribute-value
workflow-services
mbeans
uipagecontrol
unattended-processing
socketserver
nhprof
undefined-index
office-2007
addchild
entitykey
movieplayer

Resources

Encrypt Message