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

Case statement not working
Rename detailed information before $ in Terminal [closed]
Trouble in executing cake shell in cron
save terminal command to file that runs command in terminal when opened
Backslash quoting in Byron Rakitzis's RC [closed]
How to generate html file to give download link to manifest.plist file in order to install ipa to iphone
Cronjob to be scheduled [duplicate]
Shell: test if parameter is a directory
shell script to find multiple strings in multiple files and then them like “string - filename”
Fetch sftp error values in expect shell
AIX Shell Script - Formatting a long line of 255 Characters into a 10 line paragraph
Unix scripting whoami/$USER not working as desired
Calling Maple in Unix-shell without shell time overwriting
Execute large number of commands via SSH
Unix: Get the latest entry from the file
How to assign an output to a shellscript variable?

Categories

HOME
android
django
awk
apache-flink
apache-jena
css3
solaris
static-site
rds
cq5
augeas
32bit-64bit
ibeacon-android
github-enterprise
selenium-ide
onedrive-api
keytool
google-content-api
video-editing
ksh
babel
question2answer
gulp-watch
pimcore
ckfinder
expressionengine3
slidetoggle
outliers
firebase-analytics
failover
autodesk-designautomation
deltaspike
login-script
gojs
joomla2.5
hunspell
indy10
processwire
salesforce-communities
ideascript
sessionstorage
nohup
linq-to-objects
typesafe-config
setup.py
apache-stanbol
mcustomscrollbar
watchface
laravel-elixir
softmax
congestion-control
contract
drupal-theming
apache-directory
httrack
fclose
mongotemplate
podscms
page-replacement
spring-data-couchbase
excel-dna
d3-force-directed
ampps
rocks
cubism.js
vulcanize
delta
android-dateutils
avspeechsynthesizer
embedding
aurora
cortex-m
exim4
vhosts
computer-architecture
phonertc
opserver
dulwich
branch-and-bound
jsvc
avahi
omnifaces
android-broadcast
diff3
bcache
document-repository
ssis-data-flow
deform
create.js
angular-carousel
named-parameters
jquery-slider
qscrollarea
openargs
high-resolution
hidapi
virtual-pc
dopostback
sentestingkit
update-statement
non-clustered-index
openfaces
tabpanel
lxr
cuda.net

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