Parse / proc / only sets and maintains one field

I'm looking for a way to print information from / proc / mounts like this:

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

      

I'm trying to:

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

      

Anyone have a solution?

+3


source to share


1 answer


fix

  • use printf (to avoid implicit line feed)
  • add a space to separate printf from gsub output

customized 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

      

+2


source







All Articles