Solaris generally doesn't have the GNU version of anything by default. This means that the options and arguments you supply will often have to be different to get the same behaviour out of utilities like sed
.
Sometimes it will not be possible to get the same behaviour at all, for instance, sed -i
won't work on Solaris unless you have installed the GNU version of sed
.
From memory, the sed
on Solaris supports the "basic" set of regular expressions and this doesn't include the +
modifier. You can simulate a +
like this:
sed 's/[^0-9][^0-9]*//'
Or you can just use a *
for this case:
sed 's/[^0-9]*//'
Solaris usually also has the BSD versions of these utilities installed under /usr/ucb
. they are often very similar but occasionally have important differences, such as with ps
.
Bash has a "loadable" sleep which supports fractional seconds, and eliminates overheads of an external command:
$ cd bash-3.2.48/examples/loadables
$ make sleep && mv sleep sleep.so
$ enable -f sleep.so sleep
Then:
$ which sleep
/usr/bin/sleep
$ builtin sleep
sleep: usage: sleep seconds[.fraction]
$ time (for f in `seq 1 10`; do builtin sleep 0.1; done)
real 0m1.000s
user 0m0.004s
sys 0m0.004s
The downside is that the loadables may not be provided with your bash
binary, so you would need to compile them yourself as shown (though on Solaris it would not necessarily be as simple as above).
As of bash-4.4
(September 2016) all the loadables are now built and installed by default on platforms that support it, though they are built as separate shared-object files, and without a .so
suffix. Unless your distro/OS has done something creative (sadly RHEL/CentOS 8 build bash-4.4
with loadable extensions deliberately removed), you should be able to do instead:
[ -z "$BASH_LOADABLES_PATH" ] &&
BASH_LOADABLES_PATH=$(pkg-config bash --variable=loadablesdir 2>/dev/null)
enable -f sleep sleep
(The man page implies BASH_LOADABLES_PATH
is set automatically, I find this is not the case in the official distribution as of 4.4.12. If and when it is set correctly you need only enable -f filename commandname
as required.)
If that's not suitable, the next easiest thing to do is build or obtain sleep
from GNU coreutils, this supports the required feature. The POSIX sleep
command is minimal, older Solaris versions implemented only that. Solaris 11 sleep
does support fractional seconds.
As a last resort you could use perl
(or any other scripting that you have to hand) with the caveat that initialising the interpreter may be comparable to the intended sleep time:
$ perl -e "select(undef,undef,undef,0.1);"
$ echo "after 100" | tclsh
Best Answer
this will work on linux maybe also on solaris
EDIT: If \s is not supported maybe this will work...
To do that in file just add
-i
to the commandIf you don't want consecutive multiple blank lines in the result, just pipe it through
uniq