how to append to a line in sed?

how to append to a line in sed?

Post by yusu » Fri, 31 Mar 2006 05:01:24



I don't want to add a line after the current line (which a/ does), I
want to add a word to the line itself. thanks.
 
 
 

how to append to a line in sed?

Post by Chris F.A. Johnso » Fri, 31 Mar 2006 05:17:46



> I don't want to add a line after the current line (which a/ does), I
> want to add a word to the line itself. thanks.

's/$/WORD/'

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 
 
 

1. Appending to a line with Sed

I am trying to append a number to each line in a file, which I know has to
be possible, I am just unable to get it working correctly.  If I have a
file:

$ cat foo
a
b
c
d

I want to run a sed command that would output the following:

$ sed '?' foo
a, 1
b, 1
c, 1
d, 1

I have looked at the append function but I can't get it to append the text
to the line, it wants to make a newline, so my output  looks like this:

$ sed 'a\
a
", 1"
b
", 1"
c
", 1"
d
", 1"

Any help on this would be appreciated.
Thanks,
Matt

2. php as php3 perhaps with htaccess

3. How do I append a line with sed

4. Fix char/raw.c to build as module]

5. sed: command line syntax for append

6. NeXTStep and lilo

7. Using sed to append line for multiple conditions

8. ATI Mobility Rage LT AGP Pro

9. How to append lines together using sed

10. Just wondering: sed could not insert or append text in the current line?

11. sed and appending data to the end of every line

12. Append to a Line in Sed

13. sed: command line syntax for append