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

gnuplot and Shell script read many files and create graphs
Running ios-sim with Jenkins
Switching rubies in shell script
Shell - renaming logfiles according to their timestamps
Use a shell script to rename a number of files depending on their contents
Tar: Directory Checksum Error
How to check if an argument has a single character in shell
Batch Files Rename sorted by date
countdown in shell without seq or jot
scala process with spaces not working correctly
Convert fonts into different types [closed]
Many to Many relationship in two files in unix [duplicate]
grep “output of cat command - every line” in a different file
File name manipulation with shell scripts: changing file extensions
Escape characters not working in gnome-shell
subtracting dates with specific format

Categories

HOME
xml
search
fpga
amp-html
swt
battery
obfuscation
error-handling
newrelic
dojo
cakephp-3.4
emscripten
visual-studio-emulator
limit
fhir
text-mining
watson-conversation
gruntfile
feathersjs
apache2.4
rubymotion
parcelable
tiki-wiki
handler
wcag
google-earth
dst
kudu
testbed
hibernate-validator
sammy.js
instantiation
hunspell
lubridate
numpy-broadcasting
timing
modernizr
recurrent-neural-network
verifiable-c
chef-solo
kill
visa
file-sharing
wc
apache-directory
flask-login
serde
tinymce-3
mongotemplate
subnet
boo
sundials
quicktime
mouseleave
universal-analytics
cd-burning
atlas
meteor-packages
winusb
parfor
greatest-n-per-group
dup
nss
maybe
pypiserver
rubaxa-sortable
extjs-grid
amiga
graphics2d
umlgraph
nodelist
verold
xml-dsig
gnumeric
drupal-nodes
breakout
inputmismatchexception
mbunit
dtmf
apache-abdera
fragmenttransaction
wcf-configuration
kqueue
jsr286
wiimote
luabind
ikimagebrowserview
landscape-portrait
tmx
cloudfiles
dot-emacs
binomial-heap
lxr
build-environment
silverlight-oob
google-wave
sqlobject
ifilter

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