我正在寻找一种从/proc/mounts 打印信息的方法:
/home /dev/md9 /dev/mapper/home home
/var/tmp /dev/md7 /dev/mapper/vartmp vartmp
我尝试:
awk '{ print $2 " " $1; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' /proc/mounts
但结果是两行:
/home /dev/mapper/home
/dev/mapper/home home
/var/tmp /dev/md7
/dev/mapper/vartmp vartmp
有没有人有解决办法?
最佳答案
修复
- use printf ( to avoid the implicit linefeed )
- add whitespace to separate the printf from the gsub output
调整命令
awk '{ printf $2 " " $1 " "; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' /proc/mounts
输入.txt
/dev/mapper/home /home blah blah blah blah
输出
$ awk '{ printf $2 " " $1 " "; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' input.txt
/home /dev/mapper/home /dev/mapper/home home
关于bash - Parse/proc/mounts 和 substitude 只有一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31769432/