Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have a list of HEX numbers from 0000 to FFFF.

I am trying to parse the list to only include text with 2 numbers 0-9 and 2 letters A-F, but am having no luck. I have been trying egrep -v [0-9]{3} and outputting the results to a file thinking that would find any entry without 3 numbers and then taking that file and doing egrep -v [0-9]{4} against the out from the previous command, but this isn't working as I still have entries with 3 and 4 numbers. I was planning on also running egrep -v [A-F]{3} and egrep -v [A-F]{4} to filter the rest but it is still not working.

Any suggestions would be greatly appreciated.

share|improve this question

Create a file like the following

~$ cat Patterns.txt 

This is the sample input

~$ cat HEX.txt 

And this is the sample output

~$ grep -f Patterns.txt HEX.txt 


There can be only 6 possible combinations in your case

Number, Number, Letter, Letter
Number, Letter, Number, Letter
Number, Letter, Letter, Number
Letter, Letter, Number, Number
Letter, Number, Letter, Number
Letter, Number, Letter, Letter

We are storing all these combinations in Patterns.txt and asking grep to use those patterns to find values from HEX.txt

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.