Regular expression to match only X number of characters from end of line

Below you will see a small excerpt from the “octeon” string in the 32b memory dam from the proprietary routing device. As you can see, it contains some corrected ASCII, the length of which is up to 16 characters from the end of the line, and then four 32-bit words (8 characters each, of course), then the address offset.

000b27a0: 41646a75 7374206f 6374656f 6e5f6970    Adjust octeon_ip
000b2850: 73740a00 00000000 6f637465 6f6e5f72    st......octeon_r
000b2870: 5f73697a 65000000 6f637465 6f6e5f72    _size...octeon_r
000b2990: 6164696e 672e0a00 6f637465 6f6e5f72    ading...octeon_r
000b29b0: 785f7369 7a650000 6f637465 6f6e5f72    x_size..octeon_r
000b3050: 780a0000 00000000 6f637465 6f6e5f70    x.......octeon_p
000b3650: 6564204f 6374656f 6e206d6f 64656c0a    ed Octeon model.
000bade0: 20307825 71780a00 6f637465 6f6e5f6c     0x%qx..octeon_l
000bafd0: 696e6720 4f637465 6f6e2045 78656375    ing Octeon Execu
000bd710: 6564204f 6374656f 6e204d6f 64656c21    ed Octeon Model!
000bd950: 4f435445 4f4e2070 61737320 3120646f    OCTEON pass 1 do
000bda20: 6564206f 6374656f 6e206d6f 64656c3a    ed octeon model:

While this data contains some useful information, tragically, the operating system (HiveOS) does not try to sequentially allocate memory or combine disparate heaps (and why should they?), So the vast majority of memory is to-be-malloc'd heap.

0004d6b0: 00000000 00000000 00000000 00000000    ................
0004d6c0: 00000000 00000000 00000000 00000000    ................
0004d6d0: 00000000 00000000 00000000 00000000    ................
0004d6e0: 00000000 00000000 00000000 00000000    ................
0004d6f0: 00000000 00000000 00000000 00000000    ................
0004d700: 00000000 00000000 00000000 00000000    ................
0004d710: 00000000 00000000 00000000 00000000    ................
0004d720: 00000000 00000000 00000000 00000000    ................
0004d730: 00000000 00000000 00000000 00000000    ................
0004d740: 00000000 00000000 00000000 00000000    ................
0004d750: 00000000 00000000 00000000 00000000    ................

, ([a-zA-z] ) , , "" ​​ , md - - , '.

, , (for line in hexdump: f.write(line[-16:]) + grep '[A-z]' f).

, , , , programmin. , Unix, Awk script.

[a-zA-z] ( , 16) - , +,? {16} , , .

+5
3

"" -v:

grep -v \.{16}$

, 16 .

man :

-v, --invert-match
, .

+3

, ? ".{16}$"

16 . $ , .


, , , : "{4}(.*?\w.*?)$" {4} , . " 16 ", , , , , . (, - , , //.)

+3

- . , 15 . ( reixx posix, \{\} not {})

grep '[^.].\{1,15\}$'

You can then pass the result to other GRPs for testing, or you can adapt the idea to another regular expression:

grep 'abc.\{1,13\}$'

will process the string "abc" in the last 16 characters.

+2
source

All Articles