I am executing the command
lsof -nPs
The output of the command:
COMMAND PID TID USER FD TYPE DEVICE SIZE NODE NAME
systemd 1 root cwd DIR 253,0 4096 128 /
docker-co 10166 10173 root 0r CHR 1,3 1028 /dev/null
sshd 10592 root mem REG 253,0 263800 67353392 /usr/lib64/security/pam_systemd.so
sshd 10592 root DEL REG 0,5 21551641 /dev/zero
sshd 10592 root 0u CHR 1,3 1028 /dev/null
Is there a way to put a dummy value to the values of field if it is empty?
for ex:
COMMAND PID TID USER FD TYPE DEVICE SIZE NODE NAME
systemd 1 null root cwd DIR 253,0 4096 128 /
docker-co 10166 10173 root 0r CHR 1,3 null 1028 /dev/null
sshd 10592 null root mem REG 253,0 263800 67353392 /usr/lib64/security/pam_systemd.so
sshd 10592 null root DEL REG 0,5 null 21551641 /dev/zero
sshd 10592 null root 0u CHR 1,3 null 1028 /dev/null
Note:
- the main issue is the TID field, it appears in CentOs 7, but doesn't in Centos 6.
- I am making a script that would work on both the Os. (CentOs 6 and CentOs 7)
- What I want to achieve is, Whenever TID appears in the output, just ignore it.
- What I thought would work to achieve the goal is, I check the number of fields in output (using NF of awk), and check if number of fields is 10 => ignore TID.
- Why it did not work? : There might be the case where the value of SIZE and DEVICE is empty. in that case, the number of the fields will be less than 10 and hence the script would not be able to handle the scenario when TID is non-empty. so, it would not be able to ignore it.
So, If there is a way to put dummy value to empty fields, it would solve the issue.
Is there a way to put a dummy token if the value is empty.? like null, so I could check and ignore if the value is null.
Any other solution to this would be a great help.
Thank you.