Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование в *nix (http://forum.oszone.net/forumdisplay.php?f=35)
-   -   Поиск grep-ом (http://forum.oszone.net/showthread.php?t=331443)

blackeangel 25-11-2017 13:26 2780056

Поиск grep-ом
 
Собственно, есть код
Код:

find /data | grep -v '/data/media'
Но при такой постановке из строк
/data/media
/data/media/folder/folder
/data/mediaservice
grep забирает все 3 строки, а надо лишь чтоб первые 2
Как быть?

CyberDaemon 03-12-2017 16:58 2782046

Цитата:

Цитата man grep
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either
be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the
end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and
the underscore.

find /data | grep -vw '/data/media'

Цитата:

/data/
/data/mediaservice

Ylik 05-12-2017 12:43 2782454

Код:

find /data | grep -v '/data/media' | head -n2
не уверен, что понял вопрос :)

DJ Mogarych 27-12-2017 16:01 2787395

Добавить вторую команду
Код:

find /data/mediaservice

Ardenen 24-02-2018 02:32 2799866

Код:

find /data | grep -v '/data/media[^/]\+'


Время: 19:33.

Время: 19:33.
© OSzone.net 2001-