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

How to grep non matching line in linux

 
Highlighted
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 7
Highlighted
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
Highlighted
Honored Contributor

Re: How to grep non matching line in linux

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

regards,
ivan
Highlighted
Frequent Advisor

Re: How to grep non matching line in linux

I want to exclude that target subdirectory

grep -v target

target(subdirectory)
Highlighted
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"
Highlighted
Honored Contributor

Re: How to grep non matching line in linux

find . * | xargs grep -v mytext
It works for me (tm)
Highlighted
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.
Highlighted
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)