Search code examples
htmlcurlterminalw3m

How do you get just one specific line of a webpage's source code from the terminal?


I am trying to get the 400th line of source code from a number of web pages via the terminal. So far, the only way I have been able to do this is by downloading the entire source code from the page (using cURL) and then extracting the line I want, but that takes a long time when iterating over lots of pages.

Is there a way to do this more efficiently, and just get a certain line of the source code from the beginning? Is there something like cURL's head -n function, except for individual lines?


Solution

  • You could do

    curl -s "$url" | head -n400 | tail -n1