Sponsored Content
Top Forums Shell Programming and Scripting Search file pattern using grep command Post 302967973 by Scrutinizer on Tuesday 1st of March 2016 09:53:34 PM
Old 03-01-2016
You are welcome..

One more note:
Code:
grep "[\*]*.Message Completed*"

should be:
Code:
grep "[*]Message Completed[*]"

or
Code:
grep "[*].*Message Completed.*[*]"

Depending on what you need to test:


Code:
grep "[\*]*.Message Completed*"     # Matches "Message Complete" preceded by an arbitrary character (.) and followed by zero
                                    # or more d's after the sentence. The matching of the literal backslash or the asterisk ([\*])
                                    # has no meaning here, because it is followed by an asterisk, which means zero or more times
                                    # so it will match, whether or not these characters are present
grep "[*]Message Completed[*]"      # Matches "Message Completed" followed by an asterisk directly before and after the sentence
grep "[*].*Message Completed.*[*]"  # Matches "Message Completed" followed by an asterisk somewhere before and after the sentence

grep uses BRE (Basic Regular Expressions) and not Unix Pattern Matching, which use a different syntax


Please learn how to use CODE tags (and not ICODE tags)

Last edited by Scrutinizer; 03-02-2016 at 08:26 PM.. Reason: Changed "one or more d's" to "zero or more d's"
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

2. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

3. Shell Programming and Scripting

search for a pattern using grep

Hi I am facing the below problem. I have set of lines in which i have to search for only the line which matches with the pattren "/" only. input:- /*+ some text */ /*+ some text */ /* Remove rows from a table of survey results. */ /* Add a survey respondent's name and answers. */ /*... (7 Replies)
Discussion started by: manasa_vs
7 Replies

4. Shell Programming and Scripting

Conditional grep command to search entire file

Let me give you a complete example what I am trying to achieve. 1. Below is the log file structure where I need 2,5 and 14th column of the logs after grepping through the linkId=1ddoic. Log file structure:- abc.com 20120829001415 127.0.0.1 app none11111 sas 0 0 N clk Mozilla/5.0... (3 Replies)
Discussion started by: kmajumder
3 Replies

5. Shell Programming and Scripting

Remove data from grep command using the pattern in the file

Hi, I writing a shell program to remove the data from output of the find which matches a list in a file I am using the below find command to get the list of files x=`find . -name test*.dat` the output of the find command is as follows test1.dat test2.dat test3.dat test4.dat... (4 Replies)
Discussion started by: pals70423
4 Replies

6. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

7. Shell Programming and Scripting

Grep command is not search the complete pattern

I am facing a problem while using the grep command in shell script. Actually I have one file (PCF_STARHUB_20130625_1) which contain below records. SH_5.55916.00.00.100029_20130601_0001_NUC.csv.gz|438|3556691115 SH_5.55916.00.00.100029_20130601_0001_Summary.csv.gz|275|3919504621 ... (2 Replies)
Discussion started by: sumit.vedi1988
2 Replies

8. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

9. Shell Programming and Scripting

Grep command to search pattern corresponding to input from user

One more question: I want to grep "COS_12_TM_4 pattern from a file look likes : "COS_12_TM_4" " ];I am taking scan_out as the input from the user. How to search "COS_12_TM_4" in the file which is corresponds to scan_out (12 Replies)
Discussion started by: Preeti Chandra
12 Replies

10. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies
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)
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy