While trying to find the answer to this sed question , I came up with strange behavior that I could not understand.
Say I have a file called data
$> cat data foo.png abCd.png bar.png baZ.png
The challenge is to use sed in a string to replace all strings with uppercase ASCII letters. Thus, the output should be:
$> cat data foo.png abCd.png bar.png baZ.png
The solution should work with non-gnu sed as well as sed on Mac
I tried to include this built-in awk in the sed replacement part:
sed -E 's/[^ ]*[AZ][^ ]*.png/'$(echo \&|awk '{printf("<%s>[%s]",$0, tolower($0))}')'/' data
Oddly, this outputs this:
foo.png <abCd.png>[abCd.png] bar.png <baZ.png>[baZ.png]
As you can see, sed collects the correct strings with uppercase alphabets and also reaches awk, but the awk tolower() function does not work and creates the same text as the input.
Can the shell expert explain this strange behavior.
source share