Answer the question
In order to leave comments, you need to log in
Regular for egrep
Good afternoon. Help me write a regular expression for a bash script.
We have at the entrance to egrep
From: =?utf-8?B?aGVscAo=?= <[email protected]>
Subject: =?utf-8?B?0J/RgNC40LLQtdGCINGF0LDQsdGALCDQvdGD0LbQvdCwINC/0L7QvNC+0YjRjCD=
=?utf-8? Qv9C + INGA0LDQsdC Bed and 0YLQtSDRgSBlZ3JlcC4g0JrQsNC6INC30LDRgdGC0LDQst +
=? = utf-8 C40YLRjCBlZ3JlcCwg0LfQsNGF0LLQsNGC0YvQstCw0YLRjCDQstGB0LUg0YHRg = Bed and??? the
to: = utf-8 B aGVscAo = = <[email protected]>? ???
outlet to get: the
Subject:? = UTF- 8? Bed and? 0J / RgNC40LLQtdGCINGF0LDQsdGALCDQvdGD0LbQvdCwINC / 0L7QvNC 0YjRjCD + =
=? utf-8? Bed and? Qv9C + INGA0LDQsdC 0YLQtSDRgSBlZ3JlcC4g0JrQsNC6INC30LDRgdGC0LDQst + =
=? utf-8? B? C40YLRjCBlZ3JlcCwg0LfQsNGF0LLQsNGC0YvQstCw0YLRjCDQstGB0LUg0YHRg =
egrep -io '^Subject:(\s*=\?(utf-8|windows-1251|koi-8r)\?(B|Q)\?[A-Za-z0-9=\+]+\ ?=)+' only returns the first line.
How to be?
Answer the question
In order to leave comments, you need to log in
Grep actually deals with line-by-line comparison. Install pcregrep.
Well, or if you absolutely need to get by with grep, then you can use the -P key.
(Subject:)(.)*(\W)*(.)*(\W)*(.)*
Tested here: rubular.com . (http://rubular.com/r/wlhqJwbex6)
Hope it helps.
And you can use awk for headers in any number of lines:
awk -F ':' 'BEGIN{key=""} {if ($2) {key=$1}; h[key][length(h[key])+1]=$0}END{for (i in h["Subject"]) print h["Subject"][i]}' /path/to/file
here everything just
divide them into blocks
1 block everything that starts with
block 2 everything that starts with To:
(1block)(2block) return only $1
As a result, your regular expression will be reduced to a couple of characters
(^Subject:.*)(To:) return $2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question