sed remove multiple set of lines in one command

is there a way with sed to removed more than one set of lines in one line?

so i mean

sed ${firstElem},${lastIndex}d web.xml > web1.xml

this will delete lines between ${firstElem},${lastIndex}

i want in the same line to do somethinkg like this (doesn't work so far)

sed ${firstElem},${lastIndex}d ; ${secondElem},${lastIndex1}d web.xml > web1.xml

at the same time delete lines between ${firstElem},${lastIndex} and ${secondElem},${lastIndex1}d

if i don't do this in one line.. indexes for the second set change.. and i need to grep for them again.. so it would be really good if i could delete the two sets simulatiously..

thanks a lot

Yes you can, but you need to use double quotes

sed "${firstElem},${lastIndex}d ; ${secondElem},${lastIndex1}d" web.xml > web1.xml

I take it the variables contain numbers or patterns in between slashes?

1 Like

correct that variables contain line numbers.. so

like delete
10 to 13 , and 45 to 47

awk 'NR!~/^(1[0-3]|4[5-7])$/' file
1 Like