LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-05-2016, 03:31 PM   #1
CaptainDerp
LQ Newbie
 
Registered: Mar 2013
Posts: 27

Rep: Reputation: Disabled
Question Problem using sed to append text to end of each line.


Hello, Im not too great with sed, and need to append the following content to the end of each line within a text file.

Code:
{type master; file /etc/namedb/blockeddomain.hosts;};

Ok, so thats just the text I want to add, heres how Im trying to do it.

Code:
sed -i 's/$/{type master; file "/etc/namedb/blockeddomain.hosts";};/' filename.txt
The problem is when I try to do it, I keep getting an error.

Code:
sed: -e expression #1, char 26: unknown option to `s'
Can anybody help me get this simple task done?

Thank you in advance

Last edited by CaptainDerp; 09-05-2016 at 03:35 PM.
 
Old 09-05-2016, 08:03 PM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 5,332

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Use an alternative delimiter to separate the parts of the substitute command (e.g. %) so that the forward slashes in the directory name are not interpreted as part of the substitute command.
Code:
sed -i 's%$%{type master; file "/etc/namedb/blockeddomain.hosts";};%' filename.txt
 
Old 09-05-2016, 11:37 PM   #3
CaptainDerp
LQ Newbie
 
Registered: Mar 2013
Posts: 27

Original Poster
Rep: Reputation: Disabled
Thank you for the fine response and wonderful solution, I am learning.
 
Old 09-06-2016, 03:34 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,489

Rep: Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310Reputation: 4310
or you may protect those / chars using backslash:
Code:
sed -i 's/$/{type master; file "\/etc\/namedb\/blockeddomain.hosts";};/' filename.txt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to append text at the end of a line in a file mia_tech Linux - General 7 02-09-2014 11:56 PM
Sed append text to end of line if line contains specific text? How can this be done? helptonewbie Linux - Newbie 4 10-23-2013 02:48 PM
sed append word at end of line if word is missing franjo124 Linux - Newbie 3 03-08-2012 09:41 PM
Attempting to append a line of text to the end of the previous line market_garden Linux - General 4 12-11-2008 12:37 PM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration