General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to grep non matching line in linux

yogesh kumar_2
Frequent Advisor

How to grep non matching line in linux

Hi

I want to grep non matching lines for particular subdirectory.For ex:

I have subdirectory name called(target) like this

ae/mfs/bcd_io/target
ae/cfs/bcd_io/target

so i have used the following command for non-matching lines

#ls | grep -v target

But it is showing the target subdirectory.

Can anyone help me out in this issue.
7 REPLIES
Oviwan
Honored Contributor

Re: How to grep non matching line in linux

Hi

in which directory do you execute
ls |grep -v target
?

btw: this is hpux forum...

regards
Ivan Krastev
Honored Contributor

Re: How to grep non matching line in linux

Use recursive ls (-R) or use find and after that grep.

regards,
ivan
yogesh kumar_2
Frequent Advisor

Re: How to grep non matching line in linux

I want to exclude that target subdirectory

grep -v target

target(subdirectory)
Peter Nikitka
Honored Contributor

Re: How to grep non matching line in linux

Hi,

drop the ls command and use find:
mkdir -p ae/mfs/bcd_io/target/sub1 ae/cfs/bcd_io/target/sub2
find ae | grep -v target
ae
ae/mfs
ae/mfs/bcd_io
ae/cfs
ae/cfs/bcd_io

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Bill McNAMARA_1
Honored Contributor

Re: How to grep non matching line in linux

find . * | xargs grep -v mytext
It works for me (tm)
AZayed
Super Advisor

Re: How to grep non matching line in linux

Hi,

How about using diff dir_1 dir_2

Regards,
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
Dennis Handly
Acclaimed Contributor

Re: How to grep non matching line in linux

If you are using ksh or a posix shell you can use:
ls !(target)