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

what does -d command with command unzip in shell scripting
merge N sorted files using shell
Removing double quotes in a CSV with decimeter inside
Shell scripting - Email script based on user input
Unix read command with option -d and IFS variable combination
7 day retention of archive files in unix
tar command unable to find file in archive
formating each string comming out of Grep
Shell script error: unexpected end of file
Delete lines from file A that is in file B
Background Function in awk
I am getting http code as 000 or Time out on server for the cURL in shell script
execute shell script program
default shell environment when remote compiling with emacs
Unable to use wildcard for SSH command
Shell script to count the the number of files modified in svn repo

Categories

HOME
cygwin
paraview
deep-learning
fuelux
fpga
pagination
ns-3
3d
serialization
xbee
cakephp-3.4
big-o
square
polling
android-json
azure-container-service
frontend
bing-maps
jquery-ui-sortable
endeca
line
stellar.js
nancy
comsol
libusb
mvc-mini-profiler
sencha-touch
inno-download-plugin
highstock
moses
scatter3d
quickfixj
glib
mnist
reactivekit
xdocreport
ogc
azure-arm
wmp
plr
smoothstate.js
angular-http
monkey-testing
mesosphere
nanoc
libgphoto2
netbeans6.8
identification
lightning
azure-cli
avx
cup
css-transforms
mouseleave
ampps
pytables
ziparchive
winusb
microstation
envi
firebase-security
phpwebsocket
uiactionsheet
nupic
rasterize
relativelayout
character-replacement
fuelcms
jdk1.7
linked-tables
botan
matlab-deployment
uvc
rrule
gamekit
apache-spark-1.3
primitive-types
sip-server
administration
big-ip
linkedin-jsapi
cbind
jama
lnk
alternate
dot42
menubar
koala
mt4j
unit-of-work
device-width
intersect
azman
google-maps-mobile
object-database
isapi-extension
dojo-dnd
xpsdocument

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