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

WGET get HEADER if 302
Unix - How do I have my shell script process more than one file from the command line?
Keep a shell or batch file from proceeding until the previous run finishes
Powershell upload file and authentificate through NTLM
Moving files older than 1 hour from one directory to another - AIX
How to execute the command after sudo su
Need to remove date string on file
monit exit status 0 when running shellscript
Fastest way to extract a column and then find its uniq items in a large delimited file
syntax error: unexpected end of file line 45
How to access shell variable in ipython
Overwrite original image after conversion
How to get difference a date greater than 6 calendar days in shell script
Sometimes I'd like to know what my shells aliases/functions are before I execute them. Can I log them without executing them?
Calculate percentage of free memory using bash scripts in linux
Renaming a set of directories according to the number of sub directories each directory contains in ubuntu

Categories

HOME
sonarqube
oracle12c
porting
gpu
formal-languages
swt
fftw
obfuscation
apiblueprint
database-normalization
discrete-mathematics
p2p
fosrestbundle
google-schemas
mautic
angular-dart
intercom
shared-libraries
gruntfile
azure-powershell
linear-algebra
null-pointer
mvc-mini-profiler
video-editing
google-picker
mapstruct
sse
nim
undertow
blade
postscript
froala
siri
has-and-belongs-to-many
subclass
nsurl
aws-codecommit
recurring-events
r-grid
wacom
getpixel
pop3
nested-lists
apiary.io
google-knowledge-graph
tex
flatmap
protein-database
health-monitoring
urlsession
doc
xbmc
rserve
activeperl
stdmap
bbpress
cpu-cache
actor-platform
winusb
lrs
vulcanize
burrows-wheeler-transform
drawstring
angular-ui-typeahead
uiactionsheet
blitline
user-management
character-replacement
dynamics-nav-2016
linklabel
dynatree
java-money
ess
dock
slash
mod-proxy
liquid-layout
snackbar
document-repository
theos
buffering
radiant
extjs2
dsym
android-usb
inputmismatchexception
beaker-testing
kogrid
cnf
nevron
css-reset
wimax
azman
relative
flex-mobile
workflow-services
landscape-portrait
luajava
squishit
request-headers
lxr
skype4java
scrubyt
business-model
pbcopy
leader

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