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

Shell Script - Segmentation Fault
Shell: find should ignore blanks
Open Arbitrary File from Access VBA as Read-Only
what does “>&” mean when followed by a file name?
MS Word Doc: Automating find/replace using Shell Scripts
Empty read on shell script
sed command creates randomly named files
Change input base in shell script with dc?
How can I use terminal to copy and rename files from multiple folders?
how to implement event handling in shell script?
A batch file I need to convert to shell [closed]
How do I create a new directory called duplicates if a file already exists when renaming in c shell
Offering a default on return in a shell script input prompt
diff on two program with same input?
Getting sed error
sed not activating in shell script

Categories

HOME
facebook-oauth
delphi-7
ggplot2
android-studio-2.2
ns-3
depth
zend-framework
interface
serialization
rendering
static-site
dojo
odoo-8
qpython
arangodb
owin
commonjs
google-chrome-app
appcelerator-studio
java.util.logging
mxgraph
frequency-distribution
flash-player
sencha-touch
google-maps-autocomplete
asciidoctor-pdf
imagemap
cgbitmapcontext
hta
perlbrew
oculus
failover
alm
dotspatial
glib
laravel-eloquent
getpixel
docfx
zoomify
graphhopper
node-mssql
tcc
stylecop
fwrite
xbmc
chai-as-promised
compiler-design
ngmaterial
arules
seq
stripe-connect
php-socket
sklearn-pandas
html-to-pdf
nullable
grass
cycle2
blitline
dynamics-nav-2016
gocql
rate-limiting
linked-tables
omnifaces
osc
spy++
draw2d-js
extjs2
amslidemenu
notorm
jeromq
workitem
poker
node-blade
fb.ui
garbage
wiimote
urlrewriter
automationelement
dot-emacs
burndowncharts
image-capture

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