Just for the record: the grep-utility in AIX has a "-p" option which makes the output the surrounding paragraph instead of only the line with the match. If you happen to be on an AIX system this should pretty much do what you want.
Because grep -p works only on empty-line-separated paragraphs you will have to "massage" your file a bit first, something like:
Hi ,
Unix.com has been life saver for me I admit :)
I am trying to extract a paragraph based on matching pattern "CREATE TABLE " from a ddl file . The paragraphs are seperated by blank line .
Input file is
#cat zip.20080604.sql1
CONNECT TO TST103
SET SESSION_USER OPSDM002
... (2 Replies)
Hi, guys. I have one question:
I need to search for a string in a file, and then extract another string from the file and assign it to a variable.
For example:
the contents of the file (group) is below:
...
ftp:x:23:
mail:x:34
...
testing:x:2001
sales:x:2002
development:x:2003
...... (6 Replies)
Hi all,
i'm new to this community. I am trying to write a script which will fetch ftp completion time of a file from a paragraph of a big text file ( which contains multiple paragraphs) . Each paragraph will have ftp details..
Now I dont know how to fetch process time within a paragraph of... (3 Replies)
Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string.
Previously, I was outputting just each paragraph with that search string with:
cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Hi all,
The following lines are taken from a long paragraph:
Labels of output orbitals: RY* RY* RY* RY* RY* RY*
1\1\GINC-COMPUTE-1-3\SP\UB3LYP\6-31G\C2H5Cr1O1(1+,5)\LIUZHEN\19-Jan-20
10\0\\# ub3lyp/6-31G pop=(nbo,savenbo) gfprint\\E101GECP\\1,5\O,0,-1.7
... (1 Reply)
continuing from my previous post, whose link is given below as a reference
https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569
consider there is create table commands in a file for eg:
CREATE TABLE `Blahblahblah` (
`id` int(11) NOT NULL... (2 Replies)
Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed
Bold letters are the stations . The whole file has multiple stations .
Below example i wanted to search... (4 Replies)
Hello guys,
I have problem with hpux shell script. I have one big text file that contains like
SOH
bla bla bla
bla bla bla
ETX SOH
bla bla bla
ETX
SOH
bla bla bla
ETX
What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules.
I would like to extract out and write to another file only the... (2 Replies)
Hi,
Its been a long time since I have used Bash to write a script so am really struggling here. Need the gurus to help me out.
uname -a
Linux lxserv01 2.6.18-417.el5
i have a text file with blocks of code written in a similar manner
******* BEGIN MESSAGE *******
Station /... (12 Replies)
Discussion started by: dsid
12 Replies
LEARN ABOUT DEBIAN
mail::mboxparser::mail::body
MboxParser::Mail::Body(3pm) User Contributed Perl Documentation MboxParser::Mail::Body(3pm)NAME
Mail::MboxParser::Mail::Body - rudimentary mail-body object
SYNOPSIS
use Mail::MboxParser;
[...]
# $msg is a Mail::MboxParser::Mail
my $body = $msg->body(0);
# or preferably
my $body = $msg->body($msg->find_body);
for my $line ($body->signature) { print $line, "
" }
for my $url ($body->extract_urls(unique => 1)) {
print $url->{url}, "
";
print $url->{context}, "
";
}
DESCRIPTION
This class represents the body of an email-message. Since emails can have multiple MIME-parts and each of these parts has a body it is not
always easy to say which part actually holds the text of the message (if there is any at all). Mail::MboxParser::Mail::find_body will help
and suggest a part.
METHODS
as_string ([strip_sig => 1])
Returns the textual representation of the body as one string. Decoding takes place when the mailbox has been opened using the decode =>
'BODY' | 'ALL' option.
If 'strip_sig' is set to a true value, the signature is stripped from the string.
as_lines ([strip_sig => 1])
Sames as as_string() just that you get an array of lines with newlines attached to each line.
NOTE: When the body is actually some encoded binary data (most commonly such a body is base64-encoded), you can still use this method.
Then you wont really get proper lines. Instead you get chunks of binary data that you should concatenate as in
my $binary = join "", $body->as_lines;
If 'strip_sig' is set to a true value, the signature is stripped from the string.
signature
Returns the signature of a message as an array of lines. Trailing newlines are already removed.
$body->error returns a string if no signature has been found.
extract_urls
extract_urls (unique => 1)
Returns an array of hash-refs. Each hash-ref has two fields: 'url' and 'context' where context is the line in which the 'url' appeared.
When calling it like $mail->extract_urls(unique => 1), duplicate URLs will be filtered out regardless of the 'context'. That's useful
if you just want a list of all URLs that can be found in your mails.
$body->error() will return a string if no URLs could be found within the body.
quotes
Returns a hash-ref of array-refs where the hash-keys are the several levels of quotation. Each array-element contains the paragraphs of
this quotation-level as one string. Example:
my $quotes = $msg->body($msg->find_body)->quotes;
print $quotes->{1}->[0], "
";
print $quotes->{0}->[0], "
";
This should print the first paragraph of the mail-body that has been quoted once and below that the paragraph that supposedly is the
reply to this paragraph. Perhaps thus:
> I had been trying to work with the CGI module
> but I didn't yet fully understand it.
Ah, it is tricky. Have you read the CGI-FAQ that
comes with the module?
Mark that empty lines will not be ignored and are part of the lines contained in the array of $quotes->{0}.
So below is a little code-snippet that should, in most cases, restore the first 5 paragraphs (containing quote-level 0 and 1) of an
email:
for (0 .. 4) {
print $quotes->{0}->[$_];
print $quotes->{1}->[$_];
}
Since quotes() considers an empty line between two quotes paragraphs as a paragraph in $quotes->{0}, the paragraphs with one quote and
those with zero are balanced. That means:
scalar @{$quotes->{0}} - DIFF == scalar @{$quotes->{1}} where DIFF is element of {-1, 0, 1}.
Unfortunately, quotes() can up to now only deal with '>' as quotation-marks.
VERSION
This is version 0.55.
AUTHOR AND COPYRIGHT
Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de>
Copyright (c) 2001-2005 Tassilo von Parseval. This program is free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
SEE ALSO perl v5.12.3 2005-12-08 MboxParser::Mail::Body(3pm)