hoclaitudau
hoclaitudau

Reputation: 13

What is a grep command performs?

Im trying to understand this unix command but im not quite an expert on this, could someone explain it more in detail?

grep '^.\{167\}02'

What does it perform?

Upvotes: 0

Views: 51

Answers (2)

Eduardo Páez Rubio
Eduardo Páez Rubio

Reputation: 1152

From the man page (man grep)

grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.

Check the part in bold: if you don't specify the files you want to search in, it will just wait and listen to your keyboard input and do a regex match for each new line that you type.

If you want to test it, I suggest you using an easier regex, maybe with less characters like this one: ^.\{3\}02 and see what happens:

$ grep '^.\{3\}02'
02
002
0002
00002 <-- this matches and will later be printed and highlighted
00002

You don't normally use grep and type lines yourself to see if matches, but give it files as argument, or another input using the pipe:

ls -la | grep '^.\{167\}02'

Upvotes: 0

Costas
Costas

Reputation: 343

Found line(s) which starts (^) from any (.) 167 symbols which has been followed by 02.

Upvotes: 1

Related Questions