LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02: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 02:35 PM.
 
Old 09-05-2016, 07:03 PM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
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, 10: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, 02:34 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

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


Reply



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 10: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 01:48 PM
sed append word at end of line if word is missing franjo124 Linux - Newbie 3 03-08-2012 08:41 PM
Attempting to append a line of text to the end of the previous line market_garden Linux - General 4 12-11-2008 11:37 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM

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

All times are GMT -5. The time now is 01:39 AM.

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
Open Source Consulting | Domain Registration