Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

migrated from stackoverflow.com Apr 29 '13 at 17:11

This question came from our site for professional and enthusiast programmers.

up vote 9 down vote accepted
grep '^0x'

^ means the starting of a line

e.g.

kent$  echo "0x002
0x003
abc
"|grep '^0x'
0x002
0x003
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .