Results 1 to 4 of 4
I have a file which looks like this:
Code:
<components>
<folder name="bin"/>
<components>
and I would like to add one line as shown below:
Code:
<components>
<folder name="bin"/>
<components>
<component ...
- 10-21-2008 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
sed append/insert
I have a file which looks like this:
and I would like to add one line as shown below:Code:<components> <folder name="bin"/> <components>
How can I do it using sed?Code:<components> <folder name="bin"/> <components> <component name="Server" />
- 10-21-2008 #2Just Joined!
- Join Date
- Oct 2008
- Posts
- 21
you can do that with echo "line you want to add " >> filetoadd
but with sed you can add this way
The "a" command appends a line after the range or pattern. This example will add a line after every line with "WORD:"
#!/bin/sh
sed '
/WORD/ a\
Add this line after every line with WORD
'
- 10-21-2008 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
First, I don't have just 3 lines in my files, its 100 lines file and I just showed few lines here. So the first method shouldn't work.
The second one will append the line with every line with WORD. I don't want that also. I just want to add a line after a line containing <components>, but that line containing component should be after "<folder name=bin>"
Please see the 2 files again
- 10-22-2008 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 21
you didn't explained that before, but here is your solution
sed '/<folder name=bin>/ {
N
/<components>/ {
a\
Add this line after
}
}' file


Reply With Quote