$ echo "a b c syscall=257 success=yes" |
sed -E 's"
h # copy input line from pattern space to hold space
s/^.*syscall=([0-9]+[0123456789]+).*$/$(ausyscall \1)/;e # get just the syscall number
t match # Conditionally jump to "match" label if above substitution succeeded
x # else revert pattern space back to original input
b end # and jump to "end" label
:match
G # append newline + hold space to pattern space
s/^([^\n]+)\n(.*syscall=)[0123456789]+(.*)$/echo "&"\2\1\3/e' # replace number with syscall name
:end
"
a b c syscall=openat success=yes
$
The e extension to s simply forks a shell and evaluates s's resulting pattern space and replaces the pattern space with the result of the executed command. So In order to mitigate any potential code-injection issues, the regex to extract the syscall number is very careful to only match numeric digits. [0-9] is not used as it could match other things in various locales. The resulting number is justthen passed to a matter of re-crafting the pattern space into something that can meaningfully beconstructed ausyscall command and executed by.
The rest of the shellsed commands are to giveensure that if there are input lines that do not contain syscall numbers, then the desired resultare left unmodified.
Note also - whenever you see the word evaluate, take this as a big warning of possible code-injection bugs. Don't use commands like this on unvetted user input.
Update:
I believe in Because this case the command is reasonably safe against code-injection attacks, because the input is already validated as beingworks on strictly numeric-only. To be extra careful that nothing untoward data, it is goingstraightforward to be executedvalidate, the rest of the matching line canbut much more care must be made into a single-quoted printf format string (I don't think any code-injection attacks possible there), and the syscall lookup as a parameter:taken with more general cases.
$ echo "a b c syscall=257 success=yes" |
sed -E "s/'/'\\\''/g; s/^([^0123456789]*)([01234567899]+)(.*)$/printf '%s%s%s' '\1' \$(ausyscall \2) '\3'/e"
a b c syscall=openat success=yes
$