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

Unix Shell: Summing up values, one per line but skipping every nth row
Shell has become very slow since upgrading OSX [closed]
How to append new lines of text to the end after cat'ing multiple line file into variable
How to find files with duplicated content in given a directory? SHELL [closed]
Named piped for STDIN to control movie player
Elixir .exs script “module is not loaded and could not be found” when using Mix
Shell to display specific record from a file in a particular format
how to work at the same time with multiple files inside file name array in linux shell script?
Path initialization: preventing “The input line is too long”
Shell script execution without interruption
Remove Leading and trailing space in field in awk
How to compile and run this code without using erlang shell
Determine if a directory is empty, delete it if it is and delete that directroy name from a separate list
Is there Shell script date Format (dd month year time) (29 Oct 2013 05:26:30)
How to insert name of file and modified time using batch/shell script and sql loader
How to suppress I/O error message for BOTH terminal output and text log (tee)?

Categories

HOME
django
assembly
deep-learning
gdb
google-spreadsheet
angular2-material
battery
appcelerator
replace
cq5
telegram-bot
android-json
iis-6
siddhi
ipmitool
intercom
favicon
gruntfile
azure-iot-hub
google-content-api
sencha-touch
database-connection
squashfs
php-mysqlidb
mongoid6
draft-js-plugins
game-theory
windows-server-2003
motion-detection
flooding
mat
firebase-analytics
user-defined-functions
winpe
nsurl
github3.py
installshield-le
roblox
engine.io
lint
playframework-2.1
doc
datacachefactory
knime
sonarlint-eclipse
dotnet-httpclient
chai-as-promised
google-cse
page-replacement
tinkerpop
java-6
edit
bbpress
pybrain
autosar
spreadjs
cortex-m
beanstalk
findfirst
aspen
np-spring
kendo-upload
jbase
toran-proxy
oracle-spatial
ons-api
poppler
mod-proxy
canvg
typeconverter
git-ftp
actionfilterattribute
variadic-templates
raygun
lambda-architecture
jjaql
maven-scm
synapse
conditionaltagsupport
getopt
chart-director
correlated-subquery
apache-whirr
gobject-introspection
w3c-geolocation
svk
updatesourcetrigger
hbm2java
sifr
echo3
cuda.net
ifilter
change-management

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