Expand your knowledge of hardware, software and supercomputing

Using grep to filter results

The command line utility “grep” is one of the most powerful and useful tools in Linux. Its most common use is to filter results from everyday commands. For instance, if you want to see all the hostnames your system has mapped out in /etc/hosts you can simply run:

$ cat /etc/hosts

But if you know you’re just looking for a specific hostname, you can pipe the output through grep:

$ cat /etc/hosts | grep head   head-ib  head-ib.cluster   head-mgmt  head-mgmt.cluster   head-ipmi  head-ipmi.cluster   head  head.cluster

This limited the search results to lines that contained the word “head,” which represents this cluster’s head node.

Another very useful grep technique is to find every instance of a word or pattern within every file in a directory or even subdirectories:

$ grep -R “words to search for” /path/to/search/in/

This will scan every file within the path you specify and find any instance of the word or words you listed.

These two examples are just the beginning of what you can do with grep. To get the full manual for the grep command, simply type:

$ man grep

Use our Breakin stress test and diagnostics tool to pinpoint hardware issues and component failures.
Check out our product catalog and use our Configurator to plan your next system and get a price estimate.

Request a Consultation from our team of HPC and AI Experts

Would you like to speak to one of our HPC or AI experts? We are here to help you. Submit your details, and we'll be in touch shortly.

  • This field is for validation purposes and should be left unchanged.