LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-30-2015, 01:40 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Rep: Reputation: 3
sed add line under a specific line in a file


I am trying to add a line under a specific line in a file.

This is the command I am using.
Code:
/bin/sed -i -e 'export s_sshhost="host.name.here1"/a export s_vpnhost="host.name.here2"' /root/testfile
This is the output
Code:
sh: 1: xport: not found
Is there something wrong with my syntax?

Thanks
 
Old 08-30-2015, 02:15 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by aristosv View Post

Is there something wrong with my syntax?
Yes, there is. Your slash before the 'a' is supposed to be the other way. Like this:
Code:
$ cat sedapp.txt 
A line
Another line
...and the final line
Code:
$ sed '/A line/ a\New line' sedapp.txt 
A line
New line
Another line
...and the final line
Best regards,
HMW
 
Old 08-30-2015, 02:25 AM   #3
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Original Poster
Rep: Reputation: 3
no that didn't do it. I get the exact same message.
 
Old 08-30-2015, 02:32 AM   #4
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Original Poster
Rep: Reputation: 3
this doesn't produce an error, but it doesn't modify the file either

Code:
/bin/sed -i -e '/export s_sshhost="host.name.here1"/ a\export s_vpnhost="host.name.here2"' /root/testfile
 
Old 08-30-2015, 02:34 AM   #5
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Original Poster
Rep: Reputation: 3
ok, my bad, it worked thanks
 
  


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
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
[SOLVED] Using a variable in sed to pick a specific line from a text file, bash Sunvic Linux - Newbie 10 08-12-2012 11:03 AM
sed add data to the back of a particular line in a text file gengwei89 Linux - Newbie 1 11-06-2011 04:31 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 07:01 PM

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

All times are GMT -5. The time now is 05:07 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
Open Source Consulting | Domain Registration