Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find lines containing a string in linux [closed]

I have a file in Linux, I would like to diplay lines which contain a specific string in that file, how to do this?

like image 278
alwbtc Avatar asked Aug 03 '12 14:08

alwbtc


People also ask

How do you search for lines of text in Linux?

Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression. When it finds a match, it prints the line with the result. The grep command is handy when searching through large log files.

Which grep command finds all the lines that have only the word Linux in file txt?

If you want to search for fixed strings only, use grep -F 'pattern' file .

How do I search for a specific line in a file in Unix?

To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file. To look for the next occurrence after the first, either press n or press / again and then press Enter .

How do I grep a line in Linux?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.


1 Answers

The usual way to do this is with grep, which uses a regex pattern to match lines:

grep 'pattern' file 

Each line which matches the pattern will be output. If you want to search for fixed strings only, use grep -F 'pattern' file.

like image 149
knittl Avatar answered Oct 14 '22 04:10

knittl