I want to translate:
"a b c syscall=257 success=yes"
into the following:
"a b c syscall=openat success=yes"
I'd like using sed group capturing regexp and replacement combined with the use of the ausyscall applied to the number extracted by the regexp group.
I tried the following under Linux/bash:
echo "a b c syscall=257 success=yes" | sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall 257)":"
echo "a b c syscall=257 success=yes" |
sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall 257)":"
It prints: a b c SYSCALL=openat success=yes as expected.
Then I tried to use the capture group #1 as the argument to ausyscall. Like this:
echo "a b c syscall=257 success=yes" | sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall \1)":"
echo "a b c syscall=257 success=yes" |
sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall \1)":"
That invokes ausyscall 1 which prints write. This is not the captured group #1 (which has a value of 257).
So I tried using \\1 instead, but that also fails:
echo "a b c syscall=257 success=yes" | sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall \\1)":"
echo "a b c syscall=257 success=yes" |
sed -e "s:syscall=\([0-9]*\):SYSCALL="$(ausyscall \\1)":"
This invokes ausyscall \1 so it fails, prints an error on stderr (Unknown syscall \1 using x86_64 lookup table) and prints a b c SYSCALL= success=yes on stdout.
It fails passing the captured value to ausyscall. I tried with single quotes, but then the call to ausyscall is not made.
Is it possible to use sed that way?
- I am only interested to know if it's expected to be able to do this with sed.
- I know it could be done with other means (perl, python script, gawk, etc), but I want to see if it is possible with sed and if the problem is related to quoting or something like that.
Is it possible with sed? If so, what am I missing?