You are not logged in.
Pages: 1
I would like to use sed to delete text that is between "anchor" tags, like this:
#startIncludeRules
the text
on
multiple lines
#endIncludeRules
How would that succeed using sed?
Offline
how's this for ugly?
i=(`grep -n IncludeRules name_of_file |awk -F: {'print $1'}`)
i[0]=$((${i[0]}+1))
i[1]=$((${i[1]}-1))
sed "${i[0]},${i[1]}"d -i name_of_file
Offline
sed -e 's/^[^#].*//;/^$/d'
should remove every line that does not start with a #, maybe that's already enough?
Offline
Thanks,Penguin and smoon
Removing # - lines is not enough,though - it is a configuration file that has other importan lines, too.
Penguin,your commands gave an error:
sed: -e expression #1, char 3: unexpected `,'
Offline
Thanks,Penguin and smoon
Removing # - lines is not enough,though - it is a configuration file that has other importan lines, too.
Penguin,your commands gave an error:
sed: -e expression #1, char 3: unexpected `,'
I get that error to if I don't change "name_of_file" instances to the actual complete path to my file. Did you do that?
Offline
yes, I tried now with full path, too - and still got that error
Offline
I can't figure out why that wont work for you. When I was testing it, I was using !#/bin/bash instead of !#/bin/sh.
What I gave you will grep any line with IncludeRules in it and delete everything between the two points. The first line may be failing. You could echo ${i[@]} after that first line to see if it actually did something and go from there.
Sorry, I can't think of an easier way to do this.
Offline
First two lines seem to work nicely, the final value of $i is 2. echo ${i[@]} returns 2 -1.
Offline
yeah it looks like ifs finding the start tag but no the end tag. Could you post this file so I can get a better understanding of whats going on?
Offline
I found another way I got help from a Gentoo sed Wiki
sed -e '/#startIncludeRules/,/#endIncludeRules/d' testfile | more > testfile
Offline
My test file is this:
testing123
12
3
#startIncludeRules
fds
dsf
dsf
sf
sd
fs
dfdsfdsf
#endIncludeRules
sfds
fdsf
dsf
dsf
sd
Offline
ah. I thought you wanted to leave the tags but delete lines between them.
Offline
My test file is this:
testing123
12
3
#startIncludeRules
fds
dsf
dsf
sf
sd
fs
dfdsfdsf
#endIncludeRules
sfds
fdsf
dsf
dsf
sd
even this worked for me :?
Oh well, glad you got it figured.
Offline
Pages: 1