0

I have a text file with thousands of lines of hex values:

0x20000804

0x20001004

0x20002004

0x20004004

0x20008004 etc etc ... (For a few thousand lines)

Is there a way to do an invert grep expression to exclude the lines with a specific character in a specific index/position?

Example: With the numbers above in a .txt file, I only want to keep the lines that DO NOT have an "8" in index/position #6

Starting with:

0x20008034

0x20000804

0x20001004

0x20002004

0x20004004

0x20008004

I should get an output of:

0x20000804

0x20001004

0x20002004

0x20004004

As these lines do NOT have the character "8" in index/position 6

  • Please clarify: Is this a text file with the literal text e. g. 0x20004004, or a binary file? – DopeGhoti Feb 5 at 18:32
  • It's the literal text "0x20004004", etc – London2nyc Feb 5 at 18:34
  • You mean position 7. – Kusalananda Feb 5 at 18:35
  • For example: "0x20008004" would be excluded from the output since the number 8 is in index 6. – London2nyc Feb 5 at 18:36
  • No, the sixth character there is a zero. – DopeGhoti Feb 5 at 18:37
3

With Grep:

grep -vE '^.{6}8' file

With Awk, using an empty field separator so each character is a field:

awk -F '' '$7 != "8"' file
3
$ grep -v '^0x....8' /path/to/datafile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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