How To Get Wikipedia Article Summaries In Linux Command Line

If you’re a Linux user and you want to quickly get a summary of a Wikipedia article without leaving the command line, there are a few ways to do it. In this tutorial, we’ll show you a couple of methods to get Wikipedia article summaries in Linux command line.

Method 1: Using curl and pup

The first method uses two command line tools, curl and pup. Curl is a tool to transfer data from or to a server, while pup is a command line tool for processing HTML. Here’s how to use them together to get a Wikipedia article summary:

  1. Open your terminal and type the following command:
  • curl -s "https://en.wikipedia.org/wiki/$(echo "your search query" | sed 's/ /_/g')" | pup 'div.mw-parser-output > p:nth-of-type(1)'
  • Replace “your search query” with the title of the Wikipedia article you want to search for.
  • Press Enter and the summary of the article will be displayed in your terminal.
  • Method 2: Using Wikit

    Another method is to use Wikit, a command line tool for searching and reading Wikipedia articles. Here’s how to use it:

    1. Install Wikit by typing the following command in your terminal:
    • sudo apt-get install wikit
  • After installation, type the following command to search for a Wikipedia article:
    • wikit "your search query"
    • Replace “your search query” with the title of the Wikipedia article you want to search for.
  • The summary of the article will be displayed in your terminal.
  • FAQs

    1. Can I use these methods to get summaries of articles in other languages?

    Yes, you can. Just replace “en” in the Wikipedia URL with the language code of the Wikipedia language you want to search in.

    2. What if I want to get a summary of a specific section in the article?

    You can modify the selector in the pup command in method 1 to select the specific section you want. For example, to select the summary of the “History” section, you can use the selector ‘div.mw-parser-output > h2:contains(“History”) + p’.

    3. Is there a limit to the length of the summary I can get?

    Yes, both methods return only the first paragraph of the article, which is usually a summary. If you want to get more content, you’ll need to use a different method or tool.

    Conclusion

    Getting a Wikipedia article summary in the Linux command line is quick and easy with these methods. Whether you prefer curl and pup or Wikit, you can now access Wikipedia information without leaving your terminal.

    Leave a Comment