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

get last line from grep search on multiple files
Automatically close MsgBox in vbscript?
shell script executing several shell scripts for cron
removing files that have extenstion .bin then printing bye
Using Net::SSH Ruby library to remote command execution that requires sudo su - another user
Display all fields except the last
use curl in shell script to substitue a variable
How to get user input right when running a shell script?
Remove extra char in the string in shell script
Shell script to merge lines separated by blank line
Using sed or awk how do you remove a pattern around a certian line
Best Option for resumable script
options or arguments passed to executables are quoted by “ ”
How to run a subcommand inside find exec
“expect” match “send” string, why?
What command to use to get the revision history of the files in a folder

Categories

HOME
shell
scikit-learn
turing-machines
cobalt
jmeter
dns
character-encoding
numbers
saml-2.0
solver
access
mips
square
vsm
google-cloud-datalab
mvc5
webix
barcode
octave
google-chrome-app
mod-security
why3
mxgraph
openbugs
tput
supervisor
comsol
symmetricds
heat
coin3d
package.json
red5
identity-management
sigma.js
connector
windows-xp
microsoft-ocr
blade
squashfs
onload
slidetoggle
flooding
underscore.js
complex-numbers
weather
autolisp
pop3
searchkit
hivemq
release
amazon-ses
bc
rfc3339
snapchat
fwrite
globalize
carrot2
azure-cli
backbone-collections
jqchart
arules
otp
branch-prediction
taocp
xcode-server
segment-io
dup
observablecollection
respondcms
appscale
angular-ui-typeahead
nupic
beanstalk
false-sharing
user-management
gocql
text-search
pax-exam
mod-proxy
ocra
apache-commons-daemon
cwrsync
fail2ban
entity-framework-4.3
adehabitathr
apache-spark-1.3
cosine-similarity
genymotion-call
gnumeric
hibernate-entitymanager
scrypt
oocss
script#
cnf
scmmanager
insert-id
fragmenttransaction
sentestingkit
objectquery
fusefabric
cgimage
expression-blend-4
mtu
photolibrary
non-clustered-index
binomial-heap
visualj#
sifr3
software-lifecycle
firefox-3
contentpresenter

Resources

Encrypt Message