我正在寻找一种方法来打印来自/ 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
有没有人有解决方案?
答案 0 :(得分:2)
<强>修复强>
- 使用printf(以避免隐式换行)
- 添加空格以将printf与gsub输出分开
调整后的命令
awk '{ printf $2 " " $1 " "; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' /proc/mounts
<强> input.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