Skip to main content
Aligned the numbers in the description with the code
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

The condition NR == 7, NR == 13 should be read as "from any input record for which NR is 137, to any input record for which NR is 17"13", where "input record" by default is a line and NR is the number of records (lines) read so far.

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

The condition NR == 7, NR == 13 should be read as "from any input record for which NR is 13, to any input record for which NR is 17", where "input record" by default is a line and NR is the number of records (lines) read so far.

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

The condition NR == 7, NR == 13 should be read as "from any input record for which NR is 7, to any input record for which NR is 13", where "input record" by default is a line and NR is the number of records (lines) read so far.

added 238 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

The condition NR == 7, NR == 13 should be read as "from any input record for which NR is 13, to any input record for which NR is 17", where "input record" by default is a line and NR is the number of records (lines) read so far.

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file

The condition NR == 7, NR == 13 should be read as "from any input record for which NR is 13, to any input record for which NR is 17", where "input record" by default is a line and NR is the number of records (lines) read so far.

added 13 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk '7'NR == 7, NR == 13 { if (/expression/) print }' <file

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk '7,13 { if (/expression/) print }' <file

Just complementing Jeff's answer with one written in sed:

sed -n '7,13 { /expression/ p; }' <file

This would print every line between lines 7 and 13 (inclusively) that matches the regular expression expression. The default output is turned off with -n so only the lines explicitly printed with the p command will be outputted.

A direct translation of the above sed script into awk:

awk 'NR == 7, NR == 13 { if (/expression/) print }' <file
added 110 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading