Tag Info

New answers tagged


Another way - use of dc is a little esoteric, but seems to work nicely here: sed -n '/problem/=;$=' prob.txt | dc -e '??r-p' sed searches prob.txt for "problem" and the last line, and uses the = command to output the line number of both. dc reads these two values onto the stack, reverses them, subracts and prints the difference.


This should delete all lines up to (and including) the problemtic one and then count the remaining lines: sed '1,/problem/d' data.txt | wc -l


Entirely with sed(albeit two command with a pipe) sed '/ddd/,//!d' file | sed '$=;d' Deletes all the line before the line and then the next command counts the lines in the new file.


{ grep -m1 match; grep -c ''; } <file That will work w/ GNU grep and an lseek()able infile. The first grep will stop at 1 -match, and the second will -count every line remaining in input. Without GNU grep: { sed '/match/q'; grep -c ''; } <file Of course, w/ grep you can use any/all of its other options besides, and stopping at one match is not at ...


Here's one way. $ cat foo aaa bbb ccc ddd eee fff $ awk '/^ddd/{a=FNR}END{print FNR-a}' foo 2 $

Top 50 recent answers are included