How to grep file with prefix pattern?

3

1

How can I grep for lines of a file wich start with a certain string?

For example, all lines with prefex 0x, where the file has the lines

0x002
0x003
abc

Output should be

0x002
0x003

John Threepwood

Posted 2013-04-29T15:07:27.917

Reputation: 243

Answers

10

grep '^0x'

^ means the starting of a line

e.g.

kent$  echo "0x002
0x003
abc
"|grep '^0x'
0x002
0x003

Kent

Posted 2013-04-29T15:07:27.917

Reputation: 791