Sponsored Content
Top Forums Shell Programming and Scripting Find a text and if condition matches then replace it Post 303022945 by singhhe on Sunday 9th of September 2018 01:45:15 PM
Old 09-09-2018
Many Thanks! Works like a charm.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find and replace text

test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh Please advise how can I replace the abc, bcd....with ABC, BCD.... (1 Reply)
Discussion started by: bobo
1 Replies

2. UNIX for Dummies Questions & Answers

Find and replace text PLEASE HELP

Dear friends please help, I have a large data file with few hundred lines. A small example is shown below: datafile is a file with few hundred lines with the third column has many different character stings: test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh I need to... (6 Replies)
Discussion started by: bobo
6 Replies

3. Shell Programming and Scripting

find text but replace a text beside it

I have an html file that looks like this (this is just a part of the html file): <td colspan="3" rowspan="1" style="text-align: center; background-color: rgb(<!-- IDENTIFIER1 -->51, 255, 51);"><small><!-- IDENTIFIER2 -->UP</small></td> This is to automatically update the status of the... (4 Replies)
Discussion started by: The One
4 Replies

4. Shell Programming and Scripting

Need to find a string, check the next line, and if it matches certain criteria, replace it with a s

Hey Fellas. I am new to scripting. I have searched through the forums and found a lot of good info, but I can't seem to get any of it to work together. I am trying to find a particular sting in a file, and if the next string matches certain criteria, replace it with a string from a csv... (6 Replies)
Discussion started by: midniteslice
6 Replies

5. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

6. Shell Programming and Scripting

Replace text inside XML file based on condition

Hi All, I want to change the name as SEQ_13 ie., <Property Name="Name">SEQ_13</Property> when the Stage Type is PxSequentialFile ie., <Property Name="StageType">PxSequentialFile</Property> :wall: Input.XML <Main> <Record Identifier="V0S13" Type="CustomStage" Readonly="0">... (3 Replies)
Discussion started by: kmsekhar
3 Replies

7. Emergency UNIX and Linux Support

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (3 Replies)
Discussion started by: nithins007
3 Replies

8. Shell Programming and Scripting

Send email if the condition matches

Hello everyone, I am trying to create function or script to send email from an address book file. Here is the file format i have, Susan:Miller:M:123 Main Street:Philadelphia:PA:17101:666-645-6666:Susan.Miller@gmail.com:07/12/1979 Robert:Langan:S:32 North Avenue:San... (5 Replies)
Discussion started by: asistant
5 Replies

9. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

10. Shell Programming and Scripting

Grepping only if condition matches

Dear Friends, I have a flat file which is as follows $cat sample 123,456,1,1,1,1 sdfas,345,1,1,1,1 dfgd,234,2,3,4,1 ggffgr,234,4,3,2,1 jkhu,354.1,1,1,1 $ I want to get output of only those lines which has '1' in 3 to 5 position. So I want output as follows 123,456,1,1,1,1... (8 Replies)
Discussion started by: anushree.a
8 Replies
Email::Find(3pm)					User Contributed Perl Documentation					  Email::Find(3pm)

NAME
Email::Find - Find RFC 822 email addresses in plain text SYNOPSIS
use Email::Find; # new object oriented interface my $finder = Email::Find->new(&callback); my $num_found - $finder->find($text); # good old functional style $num_found = find_emails($text, &callback); DESCRIPTION
Email::Find is a module for finding a subset of RFC 822 email addresses in arbitrary text (see "CAVEATS"). The addresses it finds are not guaranteed to exist or even actually be email addresses at all (see "CAVEATS"), but they will be valid RFC 822 syntax. Email::Find will perform some heuristics to avoid some of the more obvious red herrings and false addresses, but there's only so much which can be done without a human. METHODS
new $finder = Email::Find->new(&callback); Constructs new Email::Find object. Specified callback will be called with each email as they're found. find $num_emails_found = $finder->find($text); Finds email addresses in the text and executes callback registered. The callback is given two arguments. The first is a Mail::Address object representing the address found. The second is the actual original email as found in the text. Whatever the callback returns will replace the original text. FUNCTIONS
For backward compatibility, Email::Find exports one function, find_emails(). It works very similar to URI::Find's find_uris(). EXAMPLES
use Email::Find; # Simply print out all the addresses found leaving the text undisturbed. my $finder = Email::Find->new(sub { my($email, $orig_email) = @_; print "Found ".$email->format." "; return $orig_email; }); $finder->find($text); # For each email found, ping its host to see if its alive. require Net::Ping; $ping = Net::Ping->new; my %Pinged = (); my $finder = Email::Find->new(sub { my($email, $orig_email) = @_; my $host = $email->host; next if exists $Pinged{$host}; $Pinged{$host} = $ping->ping($host); }); $finder->find($text); while( my($host, $up) = each %Pinged ) { print "$host is ". $up ? 'up' : 'down' ." "; } # Count how many addresses are found. my $finder = Email::Find->new(sub { $_[1] }); print "Found ", $finder->find($text), " addresses "; # Wrap each address in an HTML mailto link. my $finder = Email::Find->new( sub { my($email, $orig_email) = @_; my($address) = $email->format; return qq|<a href="mailto:$address">$orig_email</a>|; }, ); $finder->find($text); SUBCLASSING
If you want to change the way this module works in finding email address, you can do it by making your subclass of Email::Find, which over- rides "addr_regex" and "do_validate" method. For example, the following class can additionally find email addresses with dot before at mark. This is illegal in RFC822, see Email::Valid::Loose for details. package Email::Find::Loose; use base qw(Email::Find); use Email::Valid::Loose; # should return regex, which Email::Find will use in finding # strings which are "thought to be" email addresses sub addr_regex { return $Email::Valid::Loose::Addr_spec_re; } # should validate $addr is a valid email or not. # if so, return the address as a string. # else, return undef sub do_validate { my($self, $addr) = @_; return Email::Valid::Loose->address($addr); } Let's see another example, which validates if the address is an existent one or not, with Mail::CheckUser module. package Email::Find::Existent; use base qw(Email::Find); use Mail::CheckUser qw(check_email); sub do_validate { my($self, $addr) = @_; return check_email($addr) ? $addr : undef; } CAVEATS
Why a subset of RFC 822? I say that this module finds a subset of RFC 822 because if I attempted to look for all possible valid RFC 822 addresses I'd wind up practically matching the entire block of text! The complete specification is so wide open that its difficult to construct soemthing that's not an RFC 822 address. To keep myself sane, I look for the 'address spec' or 'global address' part of an RFC 822 address. This is the part which most people consider to be an email address (the 'foo@bar.com' part) and it is also the part which contains the information necessary for delivery. Why are some of the matches not email addresses? Alas, many things which aren't email addresses look like email addresses and parse just fine as them. The biggest headache is email and usenet and email message IDs. I do my best to avoid them, but there's only so much cleverness you can pack into one library. AUTHORS
Copyright 2000, 2001 Michael G Schwern <schwern@pobox.com>. All rights reserved. Current maintainer is Tatsuhiko Miyagawa <miyagawa@bulknews.net>. THANKS
Schwern thanks to Jeremy Howard for his patch to make it work under 5.005. LICENSE
This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself. The author STRONGLY SUGGESTS that this module not be used for the purposes of sending unsolicited email (ie. spamming) in any way, shape or form or for the purposes of generating lists for commercial sale. If you use this module for spamming I reserve the right to make fun of you. SEE ALSO
Email::Valid, RFC 822, URI::Find, Apache::AntiSpam, Email::Valid::Loose perl v5.8.8 2006-03-18 Email::Find(3pm)
All times are GMT -4. The time now is 03:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy