Sponsored Content
Full Discussion: perl extract content of file
Top Forums Shell Programming and Scripting perl extract content of file Post 302602248 by amlife on Monday 27th of February 2012 01:20:22 AM
Old 02-27-2012
perl extract content of file

I'm using Mail::Internet module, which will basically filter through email content and extract the body of the message

my perl script to extract the body of the email


HTML Code:
    #!/usr/bin/perl -w
    
    use Mail::Internet;
    
    @lines = <STDIN>;
    $mi_obj = new Mail::Internet([@lines]);
    
    $mi_obj->print_body(\*STDOUT);
my email.txt file


HTML Code:
    From rsmith@test.com  Fri Feb 24 17:41:32 2012
    Return-Path: <rsmith@test.com>
    X-Original-To: datamgr@tordata1.test.com
    Delivered-To: datamgr@tordata1.test.com
    Received: from fssmtp1.test.com (fssmtp1.test.com [10.10.10.40])
    	by tordata1.test.com (Postfix) with ESMTP id 214A2E704D4
    	for <datamgr@tordata1.test.com>; Fri, 24 Feb 2012 17:41:32 -0500 (EST)
    Received: from LT1805 (unknown [172.20.51.20])
    	by fssmtp1.test.com (Postfix) with ESMTP
    	id CC1BE1C4356; Fri, 24 Feb 2012 17:41:31 -0500 (EST)
    MIME-Version: 1.0
    From: rsmith@test.com
    To: datamgr@tordata1.test.com
    Cc: knorwood@test.com
    Date: 24 Feb 2012 17:41:31 -0500
    Subject: New Number Test
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: quoted-printable
    Message-Id: <20120224224131.CC1BE1C4356@fssmtp1.test.com>
    
    2012124541=0D=0A2012124542=0D=0A2012124543=0D=0A2012124544=0D=0A2=
    013810008=0D=0A2013810009=0D=0A2013810011=0D=0A2013810012=0D=0A20=
    13810013=0D=0A2013810014=0D=0A2013810015=0D=0A2014732160=0D=0A201=
    4732161=0D=0A2015306904=0D=0A2015306905=0D=0A2016083923=0D=0A2016=
    083924
when running the script on the command line


HTML Code:
perl perl_script.pl < email.txt
I get the following output

HTML Code:
    2012124541=0D=0A2012124542=0D=0A2012124543=0D=0A2012124544=0D=0A2=
    013810008=0D=0A2013810009=0D=0A2013810011=0D=0A2013810012=0D=0A20=
    13810013=0D=0A2013810014=0D=0A2013810015=0D=0A2014732160=0D=0A201=
    4732161=0D=0A2015306904=0D=0A2015306905=0D=0A2016083923=0D=0A2016=
    083924
which is perfectly file, however I only want to see the numbers before the first = sign on each line.

HTML Code:
    2012124541
     013810008
    13810013
    4732161

how can I achieve that???

your help is highly appreciated
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract content from a file and insert to another file

please help for the following task... I have to extract the mac address & IP address from the file1: ... 0100004512EEF4 03 192.168.0.7 192.168.0.1 -1 ... 0100779hF5D212 03 192.168.0.8 192.168.0.1 -1 ... 0100789lF5D212 03 192.168.0.9 192.168.0.1 -1 ... ... change the format (addidng... (15 Replies)
Discussion started by: fredao
15 Replies

2. Shell Programming and Scripting

Content extract of a file using awk

Hi Everyone, I have a file with the below content: File1.txt ====== ### ###==> the below table was created for testing1 purpose; ### create table 123 ( field1 date, field2 char(10) primary key(field1) ); ### ###==> the below table was created... (5 Replies)
Discussion started by: nr_shan
5 Replies

3. Shell Programming and Scripting

Extract specific content from a file

My input file: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF SDGFDGSFDGSGSDGSDGSDGSDGSDG My... (22 Replies)
Discussion started by: patrick87
22 Replies

4. Shell Programming and Scripting

[ask]awk in csh to extract content from file

Please suggest a method (in c shell or any other shell) to implement following: -To read file1.txt (sample file1 given below) -To save name field in a variable <name> -To save parameter field in a variable <parameter> for ex. let a line in file1.txt be : bill height weight the extracted... (12 Replies)
Discussion started by: animesharma
12 Replies

5. Shell Programming and Scripting

Extract XML content from a file

310439 2012-01-11 03:44:42,291 INFO PutServlet:? - Content of the Message is:="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED> 310440 <BATCH_ID>12345678519</BATCH_ID> 310441 <UID>3498748823</UID> 310442 <FEED_TYPE>FULL</FEED_TYPE> 310443 <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME> 310444... (11 Replies)
Discussion started by: arukuku
11 Replies

6. Shell Programming and Scripting

Extract Content from a file

I have an input file with contents like: ./prbru6/12030613.LOG:24514|APPL|prbru6.8269.RTUDaemon.1|?|13:49:56|12/03/06|GMT+3|?|RTUServer Error:Count of Internal Error Qty (-1) < 0, for Audit group id - 1L5XVJ6DQE36AXL, after record number,1, File: EventAuditor.cc, Line: 394|? ... (5 Replies)
Discussion started by: rkrish
5 Replies

7. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

8. Shell Programming and Scripting

Changing file content in perl

Hi All, I have a file content like this. #<clear_category_list> #<include file="SUITE:Provision-FLEXPONDER_FAC.inc"> #<include file="CAT:SYSTEM:SAS_U23.inc"> #<include file="CAT:PRIORITY:10.inc"> #<include file="CAT:FAC_TYPE:OC48.inc"> #<include file="CAT:FAC_TYPE:OC192.inc">... (2 Replies)
Discussion started by: Syed Imran
2 Replies

9. Solaris

Extract content of .dump file

We have been provided a .dump file.The need is to extract the contents(may includes files and folder). ls -lZ didnt help me as Z is not a valid option. How to extract the file contents ? (7 Replies)
Discussion started by: vinil
7 Replies

10. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies
HTML::FormatMarkdown(3) 				User Contributed Perl Documentation				   HTML::FormatMarkdown(3)

NAME
HTML::FormatMarkdown - Format HTML as Markdown VERSION
version 2.11 SYNOPSIS
use HTML::FormatMarkdown; my $string = HTML::FormatMarkdown->format_file( 'test.html' ); open my $fh, ">", "test.md" or die "$! "; print $fh $string; close $fh; DESCRIPTION
HTML::FormatMarkdown is a formatter that outputs Markdown. HTML::FormatMarkdown is built on HTML::Formatter and documentation for that module applies to this - especially "new" in HTML::Formatter, "format_file" in HTML::Formatter and "format_string" in HTML::Formatter. INSTALLATION
See perlmodinstall for information and options on installing Perl modules. BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Format>. AVAILABILITY
The project homepage is <https://metacpan.org/release/HTML-Format>. The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you, or see <https://metacpan.org/module/HTML::Format/>. AUTHORS
o Nigel Metheringham <nigelm@cpan.org> o Sean M Burke <sburke@cpan.org> o Gisle Aas <gisle@ActiveState.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Nigel Metheringham, 2002-2005 Sean M Burke, 1999-2002 Gisle Aas. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2017-10-06 HTML::FormatMarkdown(3)
All times are GMT -4. The time now is 10:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy