: ) wonderful world ( :

the metasyntactic variable

grep multiline entities

leave a comment »

In case you have a good separator of multiline entities in a file:

$ ls
update.log
$ cat update.log
Id: 2837
Field1: foo
Field2: bar
Field3: 12.4
---

Id: 44323
Field1: qux
Field2: xxyy
Status: ERROR

Id: 74738
Field1: baz
Field3: boo

$ csplit update.log '/^Id:/' '{*}'
0
51
50
35
$ ls
update.log  xx00  xx01  xx02  xx03
$ grep 'Status: ERROR' xx*
xx02:Status: ERROR
$ grep 'Status: ERROR' xx* | cut -d':' -f1 | xargs -n1 head -1
Id: 44323
$

 

Advertisement

Written by grault

November 21, 2011 - 3:51 pm at November 21, 2011 - 3:51 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.