Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer

Create a file like the following

~$ cat Patterns.txt 
[0-9][0-9][A-F][A-F]
[0-9][A-F][0-9][A-F]
[0-9][A-F][A-F][0-9]
[A-F][A-F][0-9][0-9]
[A-F][0-9][A-F][0-9]
[A-F][0-9][0-9][A-F]
~$ 

This is the sample input

~$ cat HEX.txt 
FFFF
08FF
F0AA
FF08
0F0F
F0F0
~$ 

And this is the sample output

~$ grep -f Patterns.txt HEX.txt 
08FF
FF08
0F0F
F0F0

Explanation:

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
add comment

Your Answer

 
discard

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.