I need to extract NFS mount information using mount
on Linux (RHEL 4/5) and Solaris (Solaris 10) systems. As this is part of an SSH command, the extraction needs to happen in one line. Unfortunately, Linux and Solaris display the mountpoint at different parts of the line:
Linux:
10.0.0.1:/remote/export on /local/mountpoint otherstuff
Solaris:
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
I would like to get the following space separated output
10.0.0.1 /remote/export /local/mountpoint
I managed to do it separately with sed
(Solaris 10 sed
), but I need one command returing the same output for both.
Linux sed
:
sed 's/\([^:]*\):\([^ ]*\)[^\/]*\([^ ]*\) .*/\1 \2 \3/'
Solaris sed
:
sed 's/\([^ ]*\) *on *\([^:]*\):\([^ ]*\) .*/\2 \3 \1/'
Solution:
I adapted the accepted answer to also work with DNS names and not only IPs:
awk -F'[: ]' '{if(/^\//)print $3,$4,$1;else print $1,$2,$4}'
awk could help you:
awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}'
see this test:
kent$ cat f
10.0.0.1:/remote/export on /local/mountpoint otherstuff
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
kent$ awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}' f
10.0.0.1 /remote/export /local/mountpoint
10.0.0.1 /remote/export /local/mountpoint