Ray,

On Tue, May 21, 2024 at 9:21 PM Ray Andrews <rayandrews@eastlink.ca> wrote:

On 2024-05-21 18:48, Mark J. Reed wrote:
Running lsof | grep seems a bit silly. Can't you just do lsof $mountpoint?

When I want to select columns I usually reach for awk:

 sudo lsof $mountpoint | awk '{print $1, $NF}'

Beautiful, nuts' I just presumed I needed to grep for that. Much faster your way.  As for awk, I don't know anything about it, but googling for help on various issues, one sees awk coming to the rescue all the time.  I half way learned sed, but I think I should have learned awk. One little thing, can I have the first and last columns, but with a tab between, or some other columnizer?:

COMMAND    NAME
zsh        /mnt/sda/5/boot
geany      /mnt/sda/5/boot

Maybe something like this would work for you.  Except for lsof it is all shell code.

L=15  # insure first field reserves L columns (adjust as needed)
lsof $mountpoint | \
  while read -r line ; do
    print -- ${(r.L.. .)${=line}[1]} ${${=line}[-1]}
  done

Regards,

Jim Murphy