In sed & awk, you can precede a command to select just the lines you want, and then in sed use the substitute command, or in awk print out just the fields you need.
Code:
sed -n '3s/<td>\(.*\) <\/td>/\1/p;6s/<td>\(.*\) <\/td>/\1/p' sample
21.7 kb/s (0.9%)
7768.0 b/s (0.3%)
The example given before, "sed -n '3,6p' file", will actually print the lines between 3 and 6 inclusive.
This might be a better version:
Code:
sed -n 's/<td>\(.*\) <\/td>/\1/;3p;6p;7q' sample
21.7 kb/s (0.9%)
7768.0 b/s (0.3%)
Every line has the tags removed but only lines 3 & 6 are printed. When it gets to line 7, sed quits. This can save time if you have a very long file.
Note that there is a slight irregularity in your sample file. On the 19th line there isn't a space before the end tag. If this wasn't a mistake, then remove the space before the endtag in the sed program to handle such a case:
example:
Code:
sed -n 's/<td>\(.*\)<\/td>/\1/;3p;6p;19p;20q' sample
Otherwise the tags will be in the output. This way however, there will be a space at the end of the line.
Or you could add another sed command to remove any trailing spaces:
Code:
sed -n 's/<td>\(.*\)<\/td>/\1/;s/ *$//;3p;6p;19p;20q' sample