1.

How Do I Address All The Lines Between Re1 And Re2, Excluding The Lines Themselves?

Answer»

Normally, to address the lines between two regular expressions, RE1 and RE2, one would do this: '/RE1/,/RE2/{commands;}'. Excluding those lines TAKES an extra step. To put 2 arrows before each line between RE1 and RE2, except for those lines:

sed '1,/RE1/!{ /RE2/,/RE1/!s/^/>>/; }' input.fil

The preceding script, though short, MAY be DIFFICULT to follow. It also requires that /RE1/ cannot occur on the first line of the input file. The following script, though it's not a one-liner, is easier to read and it permits /RE1/ to appear on the first line:

# sed script to replace all lines between /RE1/ and /RE2/,
# without matching /RE1/ or /RE2/
/RE1/,/RE2/{
/RE1/b
/RE2/b
s/^/>>/
}
#---END of script---

Normally, to address the lines between two regular expressions, RE1 and RE2, one would do this: '/RE1/,/RE2/{commands;}'. Excluding those lines takes an extra step. To put 2 arrows before each line between RE1 and RE2, except for those lines:

sed '1,/RE1/!{ /RE2/,/RE1/!s/^/>>/; }' input.fil

The preceding script, though short, may be difficult to follow. It also requires that /RE1/ cannot occur on the first line of the input file. The following script, though it's not a one-liner, is easier to read and it permits /RE1/ to appear on the first line:

# sed script to replace all lines between /RE1/ and /RE2/,
# without matching /RE1/ or /RE2/
/RE1/,/RE2/{
/RE1/b
/RE2/b
s/^/>>/
}
#---end of script---



Discussion

No Comment Found