Moker
Moker

Reputation: 49

Parse /proc/mounts and substitude only one field

I am looking for a way to print informations from /proc/mounts like that:

/home     /dev/md9    /dev/mapper/home    home
/var/tmp  /dev/md7    /dev/mapper/vartmp  vartmp

I try:

awk '{ print $2 " " $1; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' /proc/mounts

But the result is on two lines:

/home /dev/mapper/home
/dev/mapper/home home
/var/tmp /dev/md7
/dev/mapper/vartmp vartmp

Does anyone have a solution?

Upvotes: 3

Views: 368

Answers (1)

amdixon
amdixon

Reputation: 3833

fix

  • use printf ( to avoid the implicit linefeed )
  • add whitespace to separate the printf from the gsub output

adjusted command

awk '{ printf $2 " " $1 " "; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' /proc/mounts

input.txt

/dev/mapper/home /home blah blah blah blah

output

$ awk '{ printf $2 " " $1 " "; gsub("/","",$2); print "/dev/mapper/"$2" "$2 }' input.txt 
/home /dev/mapper/home /dev/mapper/home home

Upvotes: 2

Related Questions