SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-06-28 20:25:15

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

bash scripting: grep multiple lines

looked around the internet but not really found a working solution (or my exact question), so figured i'd ask here.

i have this example:

Options specific to device `epson2':
  Scan Mode:
    --mode Lineart|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --depth 8 [inactive]
        Number of bits per sample, typical values are 1 for "line-art" and 8
        for multibit scans.
    --dropout None|Red|Green|Blue [None]
        Selects the dropout.
    --brightness 0..0 [inactive]
        Selects the brightness.
    --sharpness -2..2 [inactive]

what i want is to remove the entries with 'inactive' (because i don't need them!)
when i use 'grep -v "inactive"' it will return just the lines without 'inactive'. but, as you can see, these are multiple-line entries. obviously i do not want the description coming with the inactive lines either. but, the description is sometimes a single line and sometimes more.
i figure what i want is a way to evaluate each '--', see if it has 'inactive', drop it if it has and skip over to the next occurrence of '--'. but i have no idea how to go about that.

so, how do i do this?

Offline

Be excellent to each other!

#2 2011-06-28 20:38:05

luc
#! Die Hard
From: Munich, Germany
Registered: 2010-03-21
Posts: 561

Re: bash scripting: grep multiple lines

maybe

grep -e -- file | grep -v inactive

Offline

#3 2011-06-28 20:53:01

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: bash scripting: grep multiple lines

luc wrote:

maybe

grep -e -- file | grep -v inactive

thanks! modified slightly, this one works like a charm!

grep -e "--*" temp.txt | grep -v "inactive"

i remember trying before to pipe grep into grep, and it did not work and i read somewhere it could but forgot how so discarded this option already! thanks again man!

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo