Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case.
I was hoping someone here could point out what it is I am doing wrong?
I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine except I noticed that some lines that were matching my pattern are missing from my output.
After doing a little digging I found that after the command matched a pattern, if the next line also matched the pattern it would fail to output the second matched pattern line.
Can any one see why its behaving this way?
Below is the command I am using
The file I am reading in is MyInputFile, the content of which is
When I run the above command my output in MyOutPutFile is
If I change the data slightly in the original MyInputFile to have line between the two matched pattern lines, like below,
Then my output Picks up both matched pattern lines in the MyOutPutFile as below.
I suppose I could double space my input file to get around this but I think it would be better to understand why its behaving this way?
if anyone was able to offer some assistance with this I would be very grateful.
Thank you very much
Paul
Last edited by Scrutinizer; 07-07-2019 at 10:24 PM..
Reason: Removed hyperlink
I have attached a file with few records. First 2 characters of each record are binary characters. I can remove it by
and it works fine. But
is behaving differently and removing more than expected characters. Can someone help me in accomplishing it through sed? Thanks in advance. (13 Replies)
Hi,
What does the following command do on files?
sed '1b; $d'
To me it just deletes the last line of the file. If so what is the significance of sed's 'b' option?
Thanks (1 Reply)
Hi, all.
Here's the problem:
sed '/FOO/,/BAR/p'
That should print anything between FOO and BAR, right?
Well, let's say I have file.txt that contains just one line "how are you today?".
Then I run something like the above and get:
$ sed '/how/,/today/p' file.txt
how are you... (9 Replies)
sed "s/^/8,A1,$dat,id2_3,/g" -e sed "s/$/,,,,,,,,,,,/g" temporary
wn m running this script m getting a error... plz help me with this....
O/p
sed: -e expression #1, char 3: unterminated `s' command
---------- Post updated at 11:35 AM ---------- Previous update was at 11:33 AM... (7 Replies)
Hi i am facing problem with sed -n option could you please help me on this, i have a file test the contents of the file is
width="75">10/0 4/12</td>^M><a href='courtorders/100412zr.pdf' target="_blank">Miscellaneous Order</a></td>^M width="75">10/01/12</td>^M><a href='courtorde... (8 Replies)
Hi,
I have the following command.(Delete all trailing blank lines at the end of a file.)
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
I don't understand the logic of this command and also I don't understand why -e is used.
Can you please let me know the logic of this command and why three -e... (5 Replies)
I accidentally saved a txt file in vi with the name ":q!".
no amount of regex tomfoolery I can think of will allow me to remove the file.
anyone got any ideas? (4 Replies)
I have 4000 files like
$cat clus_grp_seq10_g.phy
18 1002
anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG
aver_OOF92921_1 ... (1 Reply)
Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case.
I was hoping someone here could point out what it is I am doing wrong?
I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine... (2 Replies)
Discussion started by: harveyclayton
2 Replies
LEARN ABOUT DEBIAN
mail::message::body::construct
Mail::Message::Body::Construct(3pm) User Contributed Perl Documentation Mail::Message::Body::Construct(3pm)NAME
Mail::Message::Body::Construct - adds functionality to Mail::Message::Body
DESCRIPTION
This package adds complex functionality to the Mail::Message::Body class. This functions less often used, so many programs will not
compile this package.
METHODS
Constructing a body
$obj->attach(MESSAGES, OPTIONS)
Make a multipart containing this body and the specified MESSAGES. The options are passed to the constructor of the multi-part body. If
you need more control, create the multi-part body yourself. At least take a look at Mail::Message::Body::Multipart.
The message-parts will be coerced into a Mail::Message::Part, so you may attach Mail::Internet or MIME::Entity objects if you want
--see Mail::Message::coerce(). A new body with attached messages is returned.
example:
my $pgpkey = Mail::Message::Body::File->new(file => 'a.pgp');
my $msg = Mail::Message->buildFromBody(
$message->decoded->attach($pgpkey));
# The last message of the $multi multiparted body becomes a coerced $entity.
my $entity = MIME::Entity->new;
my $multi = $msg->body->attach($entity);
# Now create a new message
my $msg = Mail::Message->new(head => ..., body => $multi);
$obj->concatenate(COMPONENTS)
Concatenate a list of elements into one new body.
Specify a list of text COMPONENTS. Each component can be a message (Mail::Message, the body of the message is used), a plain body
(Mail::Message::Body), "undef" (which will be skipped), a scalar (which is split into lines), or an array of scalars (each providing
one line).
example:
# all arguments are Mail::Message::Body's.
my $sum = $body->concatenate($preamble, $body, $epilogue, "--
" , $sig);
$obj->foreachLine(CODE)
Create a new body by performing an action on each of its lines. If none of the lines change, the current body will be returned,
otherwise a new body is created of the same type as the current.
The CODE refers to a subroutine which is called, where $_ contains body's original line. DO NOT CHANGE $_!!! The result of the
routine is taken as new line. When the routine returns "undef", the line will be skipped.
example:
my $content = $msg->decoded;
my $reply = $content->foreachLine( sub { '> '.$_ } );
my $rev = $content->foreachLine( sub {reverse} );
sub filled() { length $_ > 1 ? $_ : undef }
my $nonempty = $content->foreachLine( &filled );
my $wrong = $content->foreachLine( sub {s/a/A/} ); # WRONG!!!
my $right = $content->foreachLine(
sub {(my $x=$_) =~ s/a/A/; $x} );
$obj->stripSignature(OPTIONS)
Strip the signature from the body. The body must already be decoded otherwise the wrong lines may get stripped. Returned is the
stripped version body, and in list context also the signature, encapsulated in its own body object. The signature separator is the
first line of the returned signature body.
The signature is added by the sender to tell about him- or herself. It is superfluous in some situations, for instance if you want to
create a reply to the person's message you do not need to include that signature.
If the body had no signature, the original body object is returned, and "undef" for the signature body.
-Option --Default
max_lines 10
pattern qr/^--s?$/
result_type <same as current>
max_lines => INTEGER|undef
The maximum number of lines which can be the length of a signature. Specify "undef" to remove the limit.
pattern => REGEX|STRING|CODE
Which pattern defines the line which indicates the separator between the message and the signature. In case of a STRING, this is
matched to the beginning of the line, and REGEX is a full regular expression.
In case of CODE, each line (from last to front) is passed to the specified subroutine as first argument. The subroutine must return
TRUE when the separator is found.
result_type => CLASS
The type of body to be created for the stripped body (and maybe also to contain the stripped signature)
example:
my $start = $message->decoded;
my $start = $body->decoded;
my $stripped = $start->stripSignature;
my ($stripped, $sign) = $start->stripSignature
(max_lines => 5, pattern => '-*-*-');
SEE ALSO
This module is part of Mail-Box distribution version 2.105, built on May 07, 2012. Website: http://perl.overmeer.net/mailbox/
LICENSE
Copyrights 2001-2012 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See
http://www.perl.com/perl/misc/Artistic.html
perl v5.14.2 2012-05-07 Mail::Message::Body::Construct(3pm)