shel script
|
Author | Content |
---|---|
saneesh Aug 28, 2006 8:09 PM EDT |
using sed command how to replace a single line and insert multiple lines |
cyber_rigger Aug 28, 2006 9:18 PM EDT |
You will need \n (newline) to make extra lines. You might also want to read about 'regular expressions' to set the parameters of WHAT you want to replace. Here are some one-line examples. Let's say you have a file called file1 which contains: 1 2 3 4 5 Then, using subtitution, cat file1 | sed 's/1/one/' produces: one 2 3 4 5 Using \n to make extra lines: cat file1 | sed 's/1/one\ntwo/' produces: one two 2 3 4 5 If I wanted to send this output to file2 cat file1 | sed 's/1/one\ntwo/' > file2 A shorter way to write this is sed 's/1/one\ntwo/' < file1 > file2 |
You cannot post until you login.