-3

I am trying to create a bash script for displaying only certain lines of the lsof command. I have figured out that the lsof command itself lists information in the form of columns which show info about correspondingly: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

How can I modify this info to output just the information about the command and the name of the file using it in format: COMMAND || NAME ?

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
mihaylov
  • 3
  • 2
  • 1
    So, what have you tried so far? What is not working? – Sven Nov 20 '14 at 11:05
  • Well I am not really sure how can I display the info this way. Until now I have tried using lsof -Fcn and it has displayed the commands and the names but in random order and on different lines. I am not really sure what command to use in order to archieve this and I have not managed to find relevant information on the internet. – mihaylov Nov 20 '14 at 11:20
  • `man lsof` lists all the options for controlling lsof output. – Andrew Schulman Nov 21 '14 at 09:58

1 Answers1

0

Your attempt with -F didn't work as -F is meant for a different purpose and will add newline characters after each selected field.

I've no time to wade through the options of lsof to maybe coerce it to produce the desired output, as brute forcing it is much easier:

lsof | sed -e 's/\s\s*/ /g' | cut -d' ' -f 1,9 | sed -e 's/ / || /'

Remove the last sed if you don't really want the || separator.

Sven
  • 98,649
  • 14
  • 180
  • 226