echo '0x3f 0xfa ae 0xeA' | sed '/0x[0-9a-fA-F][0-9a-fA-F]/ y/abcdef/ABCDEF/'
output:
0x3F 0xFA AE 0xEA
echo '0x3f 0xfa ae 0xeA' | sed -r '/0x[0-9a-fA-F]{2}/ y/abcdefg/ABCDEFG/'
output:
0x3F 0xFA AE 0xEA
my expected output:
0x3F 0xFA ae 0xEA
What I want to achieve is change all hexadecimals to UPPER case(only those that start with 0x), ae shouldn't be changed since it does not starts with 0x.
Why my scripts don't work?
P.S. I only want to achieve this using SED.
That will not work because the pattern will select lines, not words. If you have GNU sed, you can do this:
$ echo '0x3f 0xfa ae 0xeA' | sed 's/0x\([0-9a-fA-F][0-9a-fA-F]\)/0x\U\1/g'
0x3F 0xFA ae 0xEA
Hi, Scrutinizer
what does "\U" mean in the script?
scrutinizer:
That will not work because the pattern will select lines, not words. If you have GNU sed, you can do this:
$ echo '0x3f 0xfa ae 0xeA' | sed 's/0x\([0-9a-fA-F][0-9a-fA-F]\)/0x\U\1/g'
0x3F 0xFA ae 0xEA
ctsgnb
December 7, 2010, 12:25pm
5
shouldn't we \E if they are some further occurrence of " 'ae'-like " within the same line ?
...ooops forget it ... apply to matching pattern only right
echo '0x3f 0xfa ae 0xeA' |awk '{for (i=1;i<=NF;i++) if ($i~/^0x/) $i="0x" toupper(substr($i,3))}1'
yet another sed solution..
echo '0x3f 0xfa ae 0xeA' |sed 's/0x\(..\)/0x\U\1/g'