Sponsored Content
Top Forums Shell Programming and Scripting Concatenating and appending string based on specific pattern match Post 302380374 by Scrutinizer on Tuesday 15th of December 2009 03:43:41 AM
Old 12-15-2009
Straight forward approach:

Code:
awk -F '[ -]' '{if (NF>1){r=$1"-"$2"-"$5; m=$5;
                   if (m=="fwd"){A[r]=A[r]" "$8" "$9}
                   else if (m=="rev"){A[r]=$8" "$9" "A[r]} }
                else if (!/^$/){
                  if (m=="fwd") {B[r]=B[r]$1}
                  else {if (m=="rev") B[r]=$1B[r]} } }
                END{for (i in A) {print i, A[i]; print B[i] }}' infile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies

2. Shell Programming and Scripting

appending with sed based on matched pattern

Hi, I want to know if you can input with sed but instead of specifing a line number like below I wan't to be able to insert based on a specific word or patttern. 10i\ Insert me after line 10 is this possible with sed or should I use AWK? Thanks Jack (2 Replies)
Discussion started by: jack1981
2 Replies

3. Shell Programming and Scripting

Concatenating multiple lines to one line if match pattern

Hi all, I've been working on a script which I have hit a road block now. I have written a script using sed to extract the below data and pumped into another file: Severity............: MAJORWARNING Summary: System temperature is out of normal range. Severity............: MAJORWARNING... (13 Replies)
Discussion started by: phixsius
13 Replies

4. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies

5. Shell Programming and Scripting

Paste two file side by side together based on specific pattern match problem

Input file_1: P78811 P40108 O17861 Q6NTW1 P40986 Q6PBK1 P38264 Q6PBK1 Q9CZ49 Q1GZI0 Input file_2: (6 Replies)
Discussion started by: patrick87
6 Replies

6. Shell Programming and Scripting

Appending string to match pattern (data processing)

Hello i have go the following result from performing 2 testing using the same file. I have used unix script to extract the result because the files are many as shown below. 01_gravity.f.tcov 7 3 42.86 02_gravity.f.tcov 9 4 80.86... (4 Replies)
Discussion started by: ganiel24
4 Replies

7. Shell Programming and Scripting

Filename pattern match and appending pipe

Hi, I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records. I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each... (3 Replies)
Discussion started by: nss280
3 Replies

8. Shell Programming and Scripting

Help with replace line based on specific pattern match

Input file data20714 7327 7366 detail data20714 7327 7366 main data250821 56532 57634 detail data250821 57527 57634 main data250821 57359 57474 main data250821 57212 57301 main data250821 57140 57159 detail data250821 56834 57082 main data250821 56708 56779 main ... (3 Replies)
Discussion started by: perl_beginner
3 Replies

9. Shell Programming and Scripting

Concatenating many files based on a specific column contents

Dear all, I have many files(.csv) in a directory. I want to concatenate the files which have similar entries in a particular column and save into a new file like result_datetime.csv etc. One example file is like below. Sno,Step,Data1,Data2,Data3 etc. 1,0,2,3,4 2,1,3,4,5 3,2,0,1,1 ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

10. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies
Mail::Message::Construct::Forward(3pm)			User Contributed Perl Documentation		    Mail::Message::Construct::Forward(3pm)

NAME
Mail::Message::Construct::Forward - forwarding a Mail::Message SYNOPSIS
my Mail::Message $forward = $message->forward(To => 'you'); $forward->send; DESCRIPTION
Complex functionality on Mail::Message objects is implemented in different files which are autoloaded. This file implements the functionality related to creating forwarded messages. METHODS
Constructing a message $obj->forward(OPTIONS) Forward the content of this message. The body of the message to be forwarded is encapsulated in some accompanying text (if you have no wish for that, than "bounce" is your choice). A Mail::Message object is returned on success. You may forward a whole message, but also message parts. You may wish to overrule some of the default header settings for the reply immediately, or you may do that later with "set" on the header. When a multi-part body is encountered, and the message is included to ATTACH, the parts which look like signatures will be removed. If only one message remains, it will be the added as single attachment, otherwise a nested multipart will be the result. The value of this option does not matter, as long as it is present. See "Mail::Message::Body::Multipart". -Option --Default Bcc undef Cc undef Date <now> From <'to' in current> Message-ID <uniquely generated> Subject forwardSubject() To <required> body undef include <if body then 'NO' else C<'INLINE'>> preamble constructed from prelude and postlude signature undef Bcc => ADDRESSES Receivers of blind carbon copies: their names will not be published to other message receivers. Cc => ADDRESSES The carbon-copy receivers, by default none. Date => DATE The date to be used in the message sent. From => ADDRESSES Your identification, by default taken from the "To" field of the source message. Message-ID => STRING Supply a STRING as specific message-id for the forwarded message. By default, one is generated for you. If there are no angles around your id, they will be added. Subject => STRING|CODE Force the subject line to the specific STRING, or the result of the subroutine specified by CODE. The subroutine will be called passing the subject of the original message as only argument. By default, the forwardSubject() method is used. To => ADDRESSES The destination of your message. Obligatory. The ADDRESSES may be specified as string, a Mail::Address object, or as array of Mail::Address objects. body => OBJECT If you specify a fully prepared body OBJECT, it will be used as forwarded message contents. In this case, only the headers are constructed for you. include => 'NO'|'INLINE'|'ATTACH'|'ENCAPSULATE' Must the message where this is a reply to be included in the message? When "INLINE" is given, you may pass the options of forwardInline() as well. In many applications, the forward option "as attachment" results in a structure which is produced when this option is set to "ENCAPSULATE". Their default behavior is usually "INLINE". It is only possible to inline textual messages, therefore binary or multi-part messages will always be enclosed as attachment. Read the details in section "Creating a forward".. preamble => STRING|BODY Part which is attached before the forwarded message. If no preamble is given, then it is constructed from the prelude and postlude. When these are also not present, you will still get a one liner: the result of forwardPrelude() signature => BODY|MESSAGE The signature to be added in case of a multi-part forward. The mime-type of the signature body should indicate this is a used as such. However, in INLINE mode, the body will be taken, a line containing '-- ' added before it, and added behind the epilogue. $obj->forwardAttach(OPTIONS) Forward the message as flat attachment to the specified "preamble". You can specify all options available to "forward()", although a "preamble" which is provided as body object is required, and any specified "body" is ignored. -Option --Default preamble <required> preamble => BODY|PART $obj->forwardEncapsulate(OPTIONS) Like forwardAttach(), but in this case the original message is first encapsulated as nested message in a Mail::Message::Body::Nested, and then joint into a multipart. You can specify all options available to "forward()", although a "preamble" which is provided as body object is required, and any specified "body" is ignored. Signatures are not stripped. Signatures are not stripped. -Option --Default preamble <required> preamble => BODY|PART $obj->forwardInline(OPTIONS) This method is equivalent in behavior to forward() with the option "include" set to 'INLINE'. You can specify most of the fields which are available to forward() except "include" and "body". -Option --Default is_attached "[The forwarded message is attached] " max_signature 10 postlude undef prelude undef quote undef strip_signature qr/^--s/ is_attached => STRING A forward on binary messages can not be inlined. Therefore, they are automatically translated into an attachment, as made by forwardAttach(). The obligatory preamble option to that method may be specified as option to this method, to be used in case of such a forward of a binary, but is otherwise constructed from the prelude, the value of this option, and the postlude. max_signature => INTEGER Passed to Mail::Message::Body::stripSignature(max_lines). Only effective for single-part messages. postlude => BODY The line(s) which to be added after the quoted reply lines. Create a body for it first. This should not include the signature, which has its own option. The signature will be added after the postlude when the forwarded message is "INLINE"d. prelude => BODY The line(s) which will be added before the quoted forwarded lines. If nothing is specified, the result of the forwardPrelude() method is used. When "undef" is specified, no prelude will be added. quote => CODE|STRING Mangle the lines of an "INLINE"d reply with CODE, or by prepending a STRING to each line. The routine specified by CODE is called when the line is in $_. By default, nothing is added before each line. This option is processed after the body has been decoded. strip_signature => REGEXP|STRING|CODE Remove the signature of the sender. The value of this parameter is passed to Mail::Message::Body::stripSignature(pattern), unless the source text is not included. The signature is stripped from the message before quoting. $obj->forwardNo(OPTIONS) Construct a forward, where the whole body of the message is already constructed. That complex body is usually produced in forwardInline(), forwardAttach(), or forwardEncapsulate(). The OPTIONS are the same as for "forward()" except that "body" is required. Some other options, like "preamble", are ignored. -Option--Default body <required> body => BODY $obj->forwardPostlude() Added after the forwarded message. example: ---- END forwarded message $obj->forwardPrelude() Create a few lines to be included before the forwarded message content. The return is an array of lines. example: ---- BEGIN forwarded message From: him@somewhere.else.nl (Original Sender) To: me@example.com (Me the receiver) Cc: the.rest@world.net Date: Wed, 9 Feb 2000 15:44:05 -0500 <blank line> $obj->forwardSubject(STRING) Create a subject for a message which is a forward from this one. This routine tries to count the level of reply in subject field, and transform it into a standard form. Please contribute improvements. example: subject --> Forw: subject Re: subject --> Forw: Re: subject Re[X]: subject --> Forw: Re[X]: subject <blank> --> Forwarded DETAILS
Creating a forward The main difference between bounce() and forward() is the reason for message processing. The bounce has no intention to modify the content of message: the same information is passed-on to someplace else. This may mean some conversions, but for instance, the Message-ID does not need to be changed. The purpose of forward() is to pass on information which is modified: annotated or reduced. The information is not sent back to the author of the original message (which is implemented by reply()), but to someone else. So: some information comes in, is modified, and than forwarded to someone else. Currently, there are four ways to get the original information included, which are explained in the next sections. After the creation of the forward, you may want to rebuild() the message to remove unnecessary complexities. Of course, that is not required. forward, specify a body When you specify forward(body), you have created your own body object to be used as content of the forwarded message. This implies that forward(include) is 'NO': no automatic generation of the forwarded body. forward, inline the original The forward(include) is set to 'INLINE' (the default) This is the most complicated situation, but most often used by MUAs: the original message is inserted textually in the new body. You can set-up automatic stripping of signatures, the way of encapsulation, and texts which should be added before and after the encapsulated part. However, the result may not always be what you expect. For instance, some people use very long signatures which will not be automatically stripped because the pass the threshold. So, you probably need some manual intervention after the message is created and before it is sent. When a binary message is encountered, inlining is impossible. In that case, the message is treated as if 'ENCAPSULATE' was requested. forward, attach the original When forward(include) is explicitly set to 'ATTACH' the result will be a multipart which contains two parts. The first part will be your message, and the second the body of the original message. This means that the headers of the forwarded message are used for the new message, and detached from the part which now contains the original body information. Content related headers will (of course) still be part of that part, but lines line "To" and "Subject" will not be stored with that part. As example of the structural transformation: # code: $original->printStructure; multipart/alternative: The source message text/plain: content in raw text text/html: content as html # code: $fwd = $original->forward(include => 'ATTACH'); # code: $fwd->printStructure multipart/mixed: The source message text/plain: prelude/postlude/signature multipart/alternative text/plain: content in raw text text/html: content as html forward, encapsulate the original When forward(include) is explicitly set to 'ENCAPSULATE', then the original message is left in-tact as good as possible. The lines of the original message are used in the main message header but also enclosed in the part header. The encapsulation is implemented using a nested message, content type "message/rfc822". As example of the structural transformation: # code: $original->printStructure; multipart/alternative: The source message text/plain: content in raw text text/html: content as html # code: $fwd = $original->forward(include => 'ENCAPSULATE'); # code: $fwd->printStructure multipart/mixed: The source message text/plain: prelude/postlude/signature message/rfc822 multipart/alternative: The source message text/plain: content in raw text text/html: content as html The message structure is much more complex, but no information is lost. This is probably the reason why many MUAs use this when the forward an original message as attachment. DIAGNOSTICS
Error: Cannot include forward source as $include. Unknown alternative for the forward(include). Valid choices are "NO", "INLINE", "ATTACH", and "ENCAPSULATE". Error: Method forwardAttach requires a preamble Error: Method forwardEncapsulate requires a preamble Error: No address to create forwarded to. If a forward message is created, a destination address must be specified. 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::Construct::Forward(3pm)
All times are GMT -4. The time now is 02:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy