LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 15
sed - appending text


I tried these commands, but they wouldn't work:
Code:
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:
Code:
dialup-1:~/2testing/dir1 user1$ sed -f edits.sedscr sedTest1
Quote:
edits.sedscr
-----------------
1a\
appended text
Is there a way to do it directly on the command line?

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

Rep: Reputation: 16
Both

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

and

$ sed 1a'appended text' test|sed 1a'APPENDED TEXT'
original line 1
APPENDED TEXT
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, 03:10 PM   #3
7stud
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:
Code:
[1addr]a\
     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:
Code:
$ 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:
Code:
$ sed 'a\
>appended text' sedTest1
In that case, the text was inserted at the beginning of a line starting with line 2:
Quote:
Original text
appended textOriginal text
appended textOriginal text
appended textdialup-1:~/2testing/dir1 user1$

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


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


All times are GMT -5. The time now is 05:34 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