1

Not 100% on how to go about this.

Basically my app creates two file outputs.

file file.ext 

when searching through the directory it always returns both files. I wish only to work with

file 

how can I do a grep for just the file? Or is grep even the correct command?

!grep *.ext 

pseudo code ^

6 Answers 6

1

Why not just:

grep foobar file 

or if you want to search your directory

find . -name 'file' | xargs -r grep boofar 
Sign up to request clarification or add additional context in comments.

Comments

0

You can try using grep 'file$', i.e. select lines ending with file and nothing after that. Alternatively you can use grep -v to invert results.

# (echo "file"; echo "file.txt") | grep file$ file # (echo "file"; echo "file.txt") | grep -v .ext file 

Comments

0

I have no idea what you are trying to do with grep, but if you want to check whether a file exists, you do simply this:

if [ -r /some/path/file ]; then echo "File is readable." fi 

Comments

0

Grep has a -v flag that inverses the meaning (looks for lines that do not contain the pattern):

ls /your/directory | grep -v '\.ext$' 

This will exclude every filename ending with .ext.

Comments

0

Try

grep -v option 

-v do the inverse match

For details do $ man grep

Comments

0

To generate a list of all files that do not match a pattern, use -not in find. So you want:

find . -not -name '*.ext' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.