Not all grep implementations provide an “-o” option
2 points by textmode 3 years ago | 1 commentFor 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"
- zinekeller 3 years agoIt's not mandated by POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/g...