解析 /proc/mounts 并仅替换一个字段
Parse /proc/mounts and substitude only one field
我正在寻找一种方法来打印来自 /proc/mounts 的信息,就像这样:
/home /dev/md9 /dev/mapper/home home
/var/tmp /dev/md7 /dev/mapper/vartmp vartmp
我试试:
awk '{ print " " ; gsub("/","",); print "/dev/mapper/"" " }' /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 " " " "; gsub("/","",); print "/dev/mapper/"" " }' /proc/mounts
input.txt
/dev/mapper/home /home blah blah blah blah
输出
$ awk '{ printf " " " "; gsub("/","",); print "/dev/mapper/"" " }' input.txt
/home /dev/mapper/home /dev/mapper/home home
我正在寻找一种方法来打印来自 /proc/mounts 的信息,就像这样:
/home /dev/md9 /dev/mapper/home home
/var/tmp /dev/md7 /dev/mapper/vartmp vartmp
我试试:
awk '{ print " " ; gsub("/","",); print "/dev/mapper/"" " }' /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 " " " "; gsub("/","",); print "/dev/mapper/"" " }' /proc/mounts
input.txt
/dev/mapper/home /home blah blah blah blah
输出
$ awk '{ printf " " " "; gsub("/","",); print "/dev/mapper/"" " }' input.txt
/home /dev/mapper/home /dev/mapper/home home