Introduction

A list of solutions for common problems working in a bash shell. Will update as I find them.

Find two words existing on the same line

https://stackoverflow.com/questions/6480687/grep-for-2-words-existing-on-the-same-line

To grep for 2 words existing on the same line, simply do:

grep "word1" FILE | grep "word2"

grep “word1” FILE will print all lines that have word1 in them from FILE, and then grep “word2” will print the lines that have word2 in them. Hence, if you combine these using a pipe, it will show lines containing both word1 and word2.

Bash command to find a file and print contents

If you’re looking to find multiple files and then print the contents then this is a nice easy one. Just use some variation of find command and then cat the results. You can also use a pipe and grep to filter out the results you’re looking for.

find ... -exec cat {} \;
Useful bash Operations
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.