Not all grep implementations provide an “-o” option
For example, Plan9 grep.
Solution:
#!/bin/sh
# usage: $0 pattern < file
x=$(echo x|tr x '\34');
tr -d '\12'|sed "s/$x//g;s/$1/$x&$x/g"|tr $x '\12'|sed -n "/^$1/p" It's not mandated by POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/g...