Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-01-2007, 04:53 AM   #1
LQ Newbie
Registered: Feb 2007
Posts: 22

Rep: Reputation: 15
sed - appending text

I tried these commands, but they wouldn't work:
dialup-1:~/2testing/dir1 user1$ sed 1a"appended text" sedTest1
sed: 1: "1aappended text": command a expects \ followed by text

dialup-1:~/2testing/dir1 user1$ sed 1a\"appended text" sedTest1
(I hit ctrl+C to get back to the prompt)

dialup-1:~/2testing/dir1 user1$ sed '1a\appended text' sedTest1
sed: 1: "1a\appended text": extra characters after \ at the end of a command
However, if I use a separate file, I can make it work:
dialup-1:~/2testing/dir1 user1$ sed -f edits.sedscr sedTest1
appended text
Is there a way to do it directly on the command line?

Last edited by 7stud; 03-01-2007 at 05:08 AM.
Old 03-01-2007, 06:09 AM   #2
Registered: Dec 2005
Location: Tväråmark, Sweden
Distribution: Debian/Kubuntu
Posts: 100

Rep: Reputation: 16

$ sed 1a"appended text" test
original line 1
appended text
original line 2
original line 3


$ sed 1a'appended text' test|sed 1a'APPENDED TEXT'
original line 1
appended text
original line 2
original line 3

work for me (bash), but the best choice of delimiting character may vary with systems (a slash may be misinterpreted as catalog delimiter, etc.)
Old 03-01-2007, 02:10 PM   #3
LQ Newbie
Registered: Feb 2007
Posts: 22

Original Poster
Rep: Reputation: 15
I'm using bash on mac os x 10.4.7 if that makes any difference.

From the man pages:
     text    Write text to standard output immediately before each attempt to
             read a line of input, whether by executing the ``N'' function or
             by beginning a new cycle.
I got this to work:
$ sed -e 'a\
>appended text' sedTest1
The man pages seem to indicate that the text has to be on a separate line. Interestingly, I got different behavior if I left out the -e switch:
$ sed 'a\
>appended text' sedTest1
In that case, the text was inserted at the beginning of a line starting with line 2:
Original text
appended textOriginal text
appended textOriginal text
appended textdialup-1:~/2testing/dir1 user1$

Last edited by 7stud; 03-01-2007 at 03:05 PM.


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
Appending to a certain line in text w3stfa11 Programming 5 11-09-2006 09:33 AM
sed: appending words residing in separate file mr_scary Programming 3 10-05-2006 01:25 PM
Sed(?); Appending a comma-delineated file ice_hockey Linux - General 2 05-27-2005 08:42 AM
Appending Text Files From Bash Script alts Programming 3 11-18-2004 06:36 PM
PHP appending form fields and text. BigFred Programming 6 09-19-2003 10:02 AM > Forums > Linux Forums > Linux - Newbie

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

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