- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl Help - strip unwanted characters
Operating System - HP-UX
1752807
Members
6026
Online
108789
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2009 03:24 PM
тАО06-12-2009 03:24 PM
Hi All,
I have a Perl script with the following line:
if ( $line =~ /( ^Subject:.*? )( To: )/xms ) {
print OUTFIL $1, "\n";
}
WHich grabs the subject line of an email and writes it to a file.
I have a charset statement in the subject line in 2 - 3 places that I want to strip out
Subject line looks like:
Subject: =?ISO-8859-1?Q?Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
=?ISO-8859-1?Q?Added_lines_43)__06-12-2?=
How do I strip out the "=?ISO-8859-1?Q?" from the line?
Thanks in advance
Paul
I have a Perl script with the following line:
if ( $line =~ /( ^Subject:.*? )( To: )/xms ) {
print OUTFIL $1, "\n";
}
WHich grabs the subject line of an email and writes it to a file.
I have a charset statement in the subject line in 2 - 3 places that I want to strip out
Subject line looks like:
Subject: =?ISO-8859-1?Q?Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
=?ISO-8859-1?Q?Added_lines_43)__06-12-2?=
How do I strip out the "=?ISO-8859-1?Q?" from the line?
Thanks in advance
Paul
Solved! Go to Solution.
- Tags:
- Perl
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2009 04:00 PM
тАО06-12-2009 04:00 PM
Solution
Hi Pault:
Since this thread is really a continuation of your earlier thread here:
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1347151
...I'm going to build from it. Using this as a test file:
# cat testinput
Subject: =?ISO-8859-1?Q?Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
=?ISO-8859-1?Q?Added_lines_43)__06-12-2?=
To: me
...your amended script might look like:
# cat ./mymail
#!/usr/bin/perl
use strict;
use warnings;
my ( $line, $subject );
my @now = localtime();
my $timestamp = sprintf("%04d-%02d-%02d",$now[5]+1900, $now[4]+1, $now[3]);
my $OUTPUT = "home/share/acks/order_acks_$timestamp.txt";
#->open (OUTFIL, ">>$OUTPUT") || die "Cannot open $OUTPUT file";
{
local $/=undef;
while ($line=<>) {
chomp $line;
if ( $line =~ /( ^To:.*? )( [Cc]c:|Message-ID )/xms ) {
print $1, "\n";
}
if ( $line =~ /( ^[Cc]c:.*? )( Message-ID )/xms ) {
print "$line \n";
}
if ( $line =~ /( ^Subject:.*? )( To: )/xms ) {
( $subject = $1 ) =~ s/\Q=?ISO-8859-1?Q?\E//gxms;
print "$subject\n";
}
}
}
close OUTFIL;
exit;
...which yields:
# ./mymail testinput
Subject: Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
Added_lines_43)__06-12-2?=
I left the original logic to extract the contents of the whole subject. Then, since the string you wanted to remove occurred in several places I chose to substitute it for a null string (globally) rather than complicate the match expression and snip multiple pieces. Since the string in question has regular expression metacharacters in it, I escaped the string with '\Q...\E'. Once the $subject is collected and cleaned up we print it.
Once again, for ease of debugging, I let output go to STDOUT.
Regards!
...JRF...
Since this thread is really a continuation of your earlier thread here:
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1347151
...I'm going to build from it. Using this as a test file:
# cat testinput
Subject: =?ISO-8859-1?Q?Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
=?ISO-8859-1?Q?Added_lines_43)__06-12-2?=
To: me
...your amended script might look like:
# cat ./mymail
#!/usr/bin/perl
use strict;
use warnings;
my ( $line, $subject );
my @now = localtime();
my $timestamp = sprintf("%04d-%02d-%02d",$now[5]+1900, $now[4]+1, $now[3]);
my $OUTPUT = "home/share/acks/order_acks_$timestamp.txt";
#->open (OUTFIL, ">>$OUTPUT") || die "Cannot open $OUTPUT file";
{
local $/=undef;
while ($line=<>) {
chomp $line;
if ( $line =~ /( ^To:.*? )( [Cc]c:|Message-ID )/xms ) {
print $1, "\n";
}
if ( $line =~ /( ^[Cc]c:.*? )( Message-ID )/xms ) {
print "$line \n";
}
if ( $line =~ /( ^Subject:.*? )( To: )/xms ) {
( $subject = $1 ) =~ s/\Q=?ISO-8859-1?Q?\E//gxms;
print "$subject\n";
}
}
}
close OUTFIL;
exit;
...which yields:
# ./mymail testinput
Subject: Customer:_1111111,_Customer_PO:_123456789,_Order:_161318(?=
Added_lines_43)__06-12-2?=
I left the original logic to extract the contents of the whole subject. Then, since the string you wanted to remove occurred in several places I chose to substitute it for a null string (globally) rather than complicate the match expression and snip multiple pieces. Since the string in question has regular expression metacharacters in it, I escaped the string with '\Q...\E'. Once the $subject is collected and cleaned up we print it.
Once again, for ease of debugging, I let output go to STDOUT.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2009 06:09 PM
тАО06-12-2009 06:09 PM
Re: Perl Help - strip unwanted characters
James... thanks again! Works perfectly.
Paul
Paul
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP