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

sed with option -i and flag /d set
Command substitution in shell script without globbing
Get the local user during ssh session
How to type ^A in unix shell script/VI
Linux shell script - copy folder from VPS to local PC
How to use fnmatch from a shell?
Scrapy: Data retrieved with xpath in shell but not in item
How to write from a particular column in shell?
Cut functionality is not working in shell script
file descriptor not generated
Expect script not able to read mkdir from file and execute
converting nexus to FASTA format
Issues Trying to Run CakePHP2 Tests on Console
How to open a file in linux without specifiying editor?
Count unique values from a column of a random file by shell command
AWS CLI and difference between its versions issue

Categories

HOME
algorithm
microsoftgraph
checkstyle
c++11
string
c99
pagination
phpmyadmin
mstest
sh
grafana
newrelic
tivoli
code-coverage
missing-data
nstableheaderview
minecraft-forge
siddhi
startup
openbugs
endpoint
comsol
screen-readers
foreign-keys
identity-management
visual-glitch
exit
qliksense
epsilon
perlbrew
beautifier
bulletphysics
nsurl
custom-controls
zend-debugger
engine.io
salesforce-communities
kill
libgphoto2
opennms
yii2-api
dbcontext
lightning
carrot2
wpas
subnet
opengl-4
headless
excel-dna
reachability
usart
builtins
webjars
drawstring
firebase-security
angular-ui-typeahead
false-sharing
kendo-upload
exim4
jparsec
dynamics-nav-2016
sciruby
sha512
apache-commons-daemon
nsurlsessiondatatask
code-documentation
dbaccess
angular-gettext
mruby
browserify-shim
structuremap3
iso-prolog
paw
imagefilter
grails-domain-class
live555
mutual-authentication
ecslidingviewcontroller
wp7test
twisted.web
tree-balancing
infobright
jquery-tools
matlab-load
android-holo-everywhere
xcelsius
svk
undefined-index
facebook-iframe
hbm2java
cfwindow
tui
fail-fast-fail-early
entitykey
idatareader

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile