Jonhas
Jonhas

Reputation: 125

How to NOT detect ending '/' with regex and sed?

I've been working with a regex that finds the directories from a 'ls -lF':

sed -n '/\/$/p'

Now, I want this to work with NOT directories (i.e. files, but not symlinks). How should I do it?

Upvotes: 0

Views: 64

Answers (2)

chepner
chepner

Reputation: 531345

Don't try to parse ls. Use the appropriate predicates with the find command, or look at the primaries available with the test command.

find . ! -type d

or

for f in *; do
    if ! [ -d "$f" ]; then
        echo "$f"
    fi
done 

Upvotes: 1

shellter
shellter

Reputation: 37288

ls -lF | sed -n '/\/$/!p'
# --------------------^------

As in many places in Unix, ! negates a test. Or maybe you're familiar with -v negation in the grep family of tools.

IHTH

Upvotes: 0

Related Questions