regex to sed command in bash

Hi Folks (esp. @Kem Tekinay :slight_smile: ),

Basically, I need to add a second space in the md5 -r output of a file list. So I’m trying like this:

md5 -r $file 2>/dev/null | sed s/s/^.\\/\\{32\\}\\\\s/\\$0 /g

However, i just get back the unmodified line from the md5 output.

I have the following regex search / replace that works in Xojo (and RegExRx agrees), but I need to use it in a shell script with sed.

In RegExRx, the following does exactly what I expect:

search pattern: '^./{32]\\s'
replace pattern: '$0 '

ticks are just to delineate the entire patterns and the md5 value is always 32 characters

Example md5 output that I need to modify

fccc435755462f9c681e4cfa365d67c6 QuickArchiveDemo-20150504.144505.bru
e9d7901c1d3198d6d716407bfd0195ae QuickArchiveDemo-20150504.145527.bru
85c4716a963233dba97ebb5e776ad7a6 TGIntro.mp4
a83e800c69ffff043272f394a705385a archtime
794db038d6161babda0b8f473f0a1ae1 execbru.class

As I show above, I’ve tried

sed s/^.\\/\\{32\\}\\\\s/\\$0 /g

but it results in no change in the line or a bad substitution error depending on how I manipulate the escaping backslashes.

Anyone have an idea?

sed doesn’t recognize the \s token, and it’s overused anyway. You also need extended regular expressions with the -E switch. Try:

sed -E 's/^(.{32}) /\\1  /'

Actually, to be technically accurate, it should be:

sed -E 's/^([[:xdigit:]]{32}) /\\1  /'

The [[:digit:]] posix expression will match any hex digit.

I wanted to mark both as answers since they are both correct - the big difference is the -E switch. The [:digit:] isn’t necessary in this instance because we know what the md5 output will be.

As always, a big thanks!