Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
grep -v -A2
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Russian
View previous topic :: View next topic  
Author Message
013
n00b
n00b


Joined: 01 Mar 2007
Posts: 11
Location: Харьков.Украина

PostPosted: Tue Feb 26, 2008 11:08 pm    Post subject: grep -v -A2 Reply with quote

товарищи гуру, как заставить греп в выводе исключить искомую строку + 2 строки после?

grep SOMETHING -A2 - вывод искомого + 2 строки после
grep SOMETHING -v - вывод всего кроме SOMETHING

как сделать grep SOMETHING -v -A2 ???

возможно ли это грепом вообще?

PS: стоит grep-2.5.1a-r1
Back to top
View user's profile Send private message
asser-mag
n00b
n00b


Joined: 21 Dec 2005
Posts: 6

PostPosted: Wed Feb 27, 2008 4:10 am    Post subject: Reply with quote

grep SOMETHING -A2 | grep -v SOMETHING
Back to top
View user's profile Send private message
zvn
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2007
Posts: 77

PostPosted: Wed Feb 27, 2008 5:34 am    Post subject: Reply with quote

тут только надо помнить, что grep -A выводит указанное количество строк после последней строки с совпадением.
Back to top
View user's profile Send private message
ba
l33t
l33t


Joined: 25 May 2003
Posts: 804

PostPosted: Wed Feb 27, 2008 6:59 am    Post subject: Reply with quote

ммм... могу седом...
Code:
sed '/SOMETHING/,+2d'
Back to top
View user's profile Send private message
013
n00b
n00b


Joined: 01 Mar 2007
Posts: 11
Location: Харьков.Украина

PostPosted: Wed Feb 27, 2008 5:36 pm    Post subject: Reply with quote

Quote:
grep SOMETHING -A2 | grep -v SOMETHING

не то, сейчас пример кину

есть файл:

Code:
*  media-plugins/gst-plugins-ximagesrc [ Masked ]
      Latest version available: 0.10.7
      Latest version installed: [ Not Installed ]
      Size of files: 1,705 kB
      Homepage:      http://gstreamer.freedesktop.org/
      Description:   plugin for gstreamer
      License:       GPL-2

 media-plugins/gst-plugins-xvideo
      Latest version available: 0.10.14
      Latest version installed: 0.10.14
      Size of files: 1,587 kB
      Homepage:      http://gstreamer.freedesktop.org/
      Description:   plugin for gstreamer
      License:       GPL-2

*  media-plugins/gst-plugins-theora
      Latest version available: 0.10.14
      Latest version installed: [ Not Installed ]
      Size of files: 1,587 kB
      Homepage:      http://gstreamer.freedesktop.org/
      Description:   plugin for gstreamer
      License:       GPL-2


Я хочу вывести все установленные пакеты. Но максимум чего я смог добиться, это вывести все НЕ установленные паеты, другими словами абсолютно все, кроме того что мне надо.
Code:

cat txt-file | grep 'Not Installed' -A4 -B2

*  media-plugins/gst-plugins-theora
      Latest version available: 0.10.14
      Latest version installed: [ Not Installed ]
      Size of files: 1,587 kB
      Homepage:      http://gstreamer.freedesktop.org/
      Description:   plugin for gstreamer
      License:       GPL-2

*  media-plugins/gst-plugins-ximagesrc [ Masked ]
      Latest version available: 0.10.7
      Latest version installed: [ Not Installed ]
      Size of files: 1,705 kB
      Homepage:      http://gstreamer.freedesktop.org/
      Description:   plugin for gstreamer
      License:       GPL-2



Quote:
Code:
sed '/SOMETHING/,+2d'


спасибо Х) но теперь просто интересно как это сделать grep'ом
Back to top
View user's profile Send private message
013
n00b
n00b


Joined: 01 Mar 2007
Posts: 11
Location: Харьков.Украина

PostPosted: Wed Feb 27, 2008 9:45 pm    Post subject: Reply with quote

Quote:

Quote:

Code:
sed '/SOMETHING/,+2d'


спасибо Х) но теперь просто интересно как это сделать grep'ом


ошибочка вышла, сейчас проверил - не то он выводит. скорее всего из-за того, что я пример не выкладывал
Back to top
View user's profile Send private message
zvn
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2007
Posts: 77

PostPosted: Thu Feb 28, 2008 4:46 am    Post subject: Reply with quote

если уж говорить на примерах, то вот как можно, только я смотрел не -A, а -B
Code:

emerge -s mozilla >./1
cat ./1 |grep "Latest version installed" -B 2 >./2
cat ./2 |grep "Not Installed" -B 2 >./3
diff ./2 ./3 >./4

С другой стороны, не проще отработать
Code:

equery l
Back to top
View user's profile Send private message
013
n00b
n00b


Joined: 01 Mar 2007
Posts: 11
Location: Харьков.Украина

PostPosted: Thu Feb 28, 2008 7:27 pm    Post subject: Reply with quote

решение нашли тут:

https://forums.gentoo.org/viewtopic-t-667733.html
Back to top
View user's profile Send private message
burik666
n00b
n00b


Joined: 28 Jan 2007
Posts: 51
Location: Санкт-Петербург

PostPosted: Tue Mar 11, 2008 10:18 pm    Post subject: Reply with quote

можно так
Quote:
esearch lala|grep -E "installed:.{12}[^[]" -B 2 -A 4

_________________
Linux for you
gentoo.bloodhost.ru Gentoo mirror (Russia, Saint-Petersburg)
Back to top
View user's profile Send private message
dragon1020
n00b
n00b


Joined: 07 Jul 2006
Posts: 58
Location: Moscow, Russia

PostPosted: Tue Mar 11, 2008 10:45 pm    Post subject: Reply with quote

А можно это сделать не emerge+grep, а eix, что _значительно_ быстрее будет.

Ну или так, если интересует именно греп:
Code:
emerge -s something | grep "Latest version installed: [^[]" -B2 -A4


burik666, имхо ".{12}" там не нужно.
Back to top
View user's profile Send private message
burik666
n00b
n00b


Joined: 28 Jan 2007
Posts: 51
Location: Санкт-Петербург

PostPosted: Wed Mar 12, 2008 7:13 am    Post subject: Reply with quote

dragon1020 wrote:
burik666, имхо ".{12}" там не нужно.


Если использовать emerge -s тогда не нужен. А если esearch, то необходимо. т.к. там выделение цветом.
_________________
Linux for you
gentoo.bloodhost.ru Gentoo mirror (Russia, Saint-Petersburg)
Back to top
View user's profile Send private message
Hyperwyrm
n00b
n00b


Joined: 03 Feb 2008
Posts: 11
Location: Russia, Moscow

PostPosted: Wed Mar 12, 2008 7:51 pm    Post subject: Reply with quote

Может конечно немного не в тему, но вот как я вывожу список установленного ПО
Code:

#!/bin/sh

APPDIR=/var/db/pkg
LOGDIR=~/logs
LOGFILE=installed-apps.log

if [ ! -d ${LOGDIR} ]; then
        mkdir ${LOGDIR}
fi

cat /dev/null > ${LOGDIR}/${LOGFILE}
for app_cat in `ls ${APPDIR}`
do
        echo "${app_cat}:" >> ${LOGDIR}/${LOGFILE}
        for app_name in `ls ${APPDIR}/${app_cat}`
        do
                echo "     ${app_name}" >> ${LOGDIR}/${LOGFILE}
        done
done

if [ "$1" == "-i" ]; then
        less ${LOGDIR}/${LOGFILE}
fi
Back to top
View user's profile Send private message
burik666
n00b
n00b


Joined: 28 Jan 2007
Posts: 51
Location: Санкт-Петербург

PostPosted: Wed Mar 12, 2008 11:47 pm    Post subject: Reply with quote

find /var/db/pkg/ -name PF -exec cat {} \;

не идеал.
_________________
Linux for you
gentoo.bloodhost.ru Gentoo mirror (Russia, Saint-Petersburg)
Back to top
View user's profile Send private message
burik666
n00b
n00b


Joined: 28 Jan 2007
Posts: 51
Location: Санкт-Петербург

PostPosted: Tue Mar 18, 2008 12:17 pm    Post subject: Reply with quote

Code:
esearch -I \*

и никакого grep
_________________
Linux for you
gentoo.bloodhost.ru Gentoo mirror (Russia, Saint-Petersburg)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Russian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum