Skip to main content
added 2 characters in body
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

It seems like you're looking for words that are between 8 and 15 chars, and replace the first 8 hex digits:

sed -E 's/\<[[:xdigit:]]{8}([[:xdigit:]]{0,7})\>/00000000\1/g' <<END
abcdef12cade 12345678 abcdefba12345678 12345 123456789
END
00000000cade 00000000 abcdefba12345678 12345 000000009

Where, \< and \> are word boundaries, and [:xdigit:] matchmatches a hex digit.

It seems like you're looking for words that are between 8 and 15 chars, and replace the first 8 hex digits:

sed -E 's/\<[[:xdigit:]]{8}([[:xdigit:]]{0,7})\>/00000000\1/g' <<END
abcdef12cade 12345678 abcdefba12345678 12345 123456789
END
00000000cade 00000000 abcdefba12345678 12345 000000009

Where, \< and \> are word boundaries, and [:xdigit:] match a hex digit.

It seems like you're looking for words that are between 8 and 15 chars, and replace the first 8 hex digits:

sed -E 's/\<[[:xdigit:]]{8}([[:xdigit:]]{0,7})\>/00000000\1/g' <<END
abcdef12cade 12345678 abcdefba12345678 12345 123456789
END
00000000cade 00000000 abcdefba12345678 12345 000000009

Where, \< and \> are word boundaries, and [:xdigit:] matches a hex digit.

Post Undeleted by glenn jackman
added 19 characters in body
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

with GNU sedIt seems like you're looking for words that are between 8 and 15 chars, you can specify which match you want toand replace the first 8 hex digits:

sed -E 's/[[\<[[:xdigit:]]{8}/00000000/1; s/([[:xdigit:]]{0,7})\>/0000000000000000\1/2'g' <<END
abcdef12cade 12345678 abcdefba12345678 12345 123456789
END
00000000cade 00000000 abcdefba12345678 12345 000000009

Notes:Where, \< and \> are word boundaries, and [:xdigit:] match a hex digit.

  1. the empty regex in the 2nd s command: that re-uses the previous one.
  2. [:xdigit:] == 0-9a-fA-F

with GNU sed, you can specify which match you want to replace:

sed -E 's/[[:xdigit:]]{8}/00000000/1; s//00000000/2' <<END
abcdef12cade 12345678 abcdefba12345678
END
00000000cade 00000000 abcdefba12345678

Notes:

  1. the empty regex in the 2nd s command: that re-uses the previous one.
  2. [:xdigit:] == 0-9a-fA-F

It seems like you're looking for words that are between 8 and 15 chars, and replace the first 8 hex digits:

sed -E 's/\<[[:xdigit:]]{8}([[:xdigit:]]{0,7})\>/00000000\1/g' <<END
abcdef12cade 12345678 abcdefba12345678 12345 123456789
END
00000000cade 00000000 abcdefba12345678 12345 000000009

Where, \< and \> are word boundaries, and [:xdigit:] match a hex digit.

Post Deleted by glenn jackman
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

with GNU sed, you can specify which match you want to replace:

sed -E 's/[[:xdigit:]]{8}/00000000/1; s//00000000/2' <<END
abcdef12cade 12345678 abcdefba12345678
END
00000000cade 00000000 abcdefba12345678

Notes:

  1. the empty regex in the 2nd s command: that re-uses the previous one.
  2. [:xdigit:] == 0-9a-fA-F