How to grep a word and nth line of that word recursively?


#1

Hi

we have multiple files and directories, in that i need to grep Nth line of a word match and redirect that output to a new file.

Ex: i have a file called reports.html, in that i need to grep the word “Total” and 5th line of its value “67%” and send these to a new file.
Please help me in doing this.


#2

assuming that my HTML file to be that way:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
</head>
<body>
	<div id="app">
		<div>Total:</div>
		<div>10%</div>
		<div>20%</div>
		<div>30%</div>
		<div>40%</div>
		<div>67%</div>
	</div>
</body>
</html>

Try this:

grep -A 5 Total reports.html | awk ‘FNR == 6 { print substr($1, 6, length($1)-11) }’

Return:

67%