How to force grep to force file returns and ignore directories?

I am trying to use grep to automatically search for a bibtex program in a custom bin folder.

The problem is that it often returns a directory called bibtex, which means that the script cannot automatically execute the command.

How to make the grep command (or indeed the locate command) automatically ignore directories?

EDIT: current command: locate bibtex | grep "/bibtex$" -d skip | head -n1

+5
source share
4 answers

A sigh, not my cleanest, but it works. perl -ne 'chomp($f=$_);print if !-d $f'

which makes your team locate bibtex | perl -ne 'chomp($f=$_);print if !-d $f' | grep "/bibtex$" -d skip | head -n1

+1
source

Team find?

find /bin -name bibtex -type f

Searches for the file name "bibtex" of type "f", which is a regular file.

+12
source
locate --basename '\bibtex' --limit 1

grep head, - , .

:

type -P bibtex

which will look in PATHfor a program with this name?

+4
source

I don’t understand exactly, maybe my decision is wrong: why don’t you use which ? Or is bibtex not in PATH?

+2
source

All Articles