我需要在Linux (RHEL 4/5)和Solaris (Solaris 10)系统上使用mount
提取NFS挂载信息。由于这是SSH命令的一部分,因此提取需要在一行中进行。不幸的是,Linux和Solaris在行的不同部分显示挂载点:
Linux:
10.0.0.1:/remote/export on /local/mountpoint otherstuff
Solaris:
/local/mountpoint on 10.0.0.1:/remote/export otherstuff
我想得到以下空格分隔的输出
10.0.0.1 /remote/export /local/mountpoint
我成功地用sed
(Solaris 10 sed
)单独完成了这个任务,但是我需要一个命令为这两个命令重新执行相同的输出。
Linux sed
sed 's/\([^:]*\):\([^ ]*\)[^\/]*\([^ ]*\) .*/\1 \2 \3/'
Solaris sed
sed 's/\([^ ]*\) *on *\([^:]*\):\([^ ]*\) .*/\2 \3 \1/'
解决方案:
我对accepted answer进行了调整,使其也可以使用DNS名称,而不仅仅是IP:
awk -F'[: ]' '{if(/^\//)print $3,$4,$1;else print $1,$2,$4}'
发布于 2014-01-07 14:38:53
awk可以帮你:
awk -F'[: ]' '{if(/^[0-9]/)print $1,$2,$4;else print $3,$4,$1}'
请参阅此测试:
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
发布于 2014-01-07 16:34:46
Kents解决方案的一个浅薄版本
awk -F'[: ]' '{print /^[0-9]/?$1" "$2" "$4:$3" "$4" "$1}' file
10.0.0.1 /remote/export /local/mountpoint
10.0.0.1 /remote/export /local/mountpoint
https://stackoverflow.com/questions/20974140
复制相似问题