- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- perl delete help
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
тАО10-11-2004 06:03 AM
тАО10-11-2004 06:03 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2004 09:01 AM
тАО10-11-2004 09:01 AM
SolutionHere is one way to do it. Create a Perl script that will match a range of lines and skip them, otherwise printing the lines. Something like this:
#!/usr/bin/perl
# noheader.pl
while (<>) {
if (/Received:/ .. /DeliveredDate:/) {
next;
} else {
print;
}
}
Now, just run it like this:
./noheader.pl <159191.txt
and it should just print the text you need.
Of course, there are even shorter ways to do it. After I played with this for a bit I figured out that this would also work:
while (<>) {
print unless (/Received:/ .. /DeliveredDate:/);
}
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2004 02:46 PM
тАО10-11-2004 02:46 PM
Re: perl delete help
In perl can I have the script to run for over 500 different files at once? Is there a way to avoid entering the file name for every file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2004 02:19 AM
тАО10-12-2004 02:19 AM
Re: perl delete help
You can use the '-i' option from the Perl command line to edit the file in place. Something like this should work:
perl -i -n -e 'print unless (/Received:/ .. /DeliveredDate:/);' 159191.txt
There are a couple of ways to handle it with a bunch of files. One way would be to put the line above into a small shell script:
for f in *.txt
do
perl -i -n -e 'print unless (/Received:/ .. /DeliveredDate:/);' $f
done
You could also use the file handling machinery inside of Perl and do it in a single script.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 12:22 PM
тАО10-13-2004 12:22 PM
Re: perl delete help
I put the following in a script as you suggested:
for $f in *.txt
do
perl -i -n -e 'print unless (/Received:/ .. /DeliveredDate:/);'$f
done
I get this error message:
'Missing $ on loop variable at test.pl line 1.'
Am I doing something wrong? Do I need to assign a directory where the files are located?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 12:51 PM
тАО10-13-2004 12:51 PM
Re: perl delete help
It looks like you left out the space between the last single quote and the dollar f variable.
You should be able to run this from the directory where your files are located, or else you can specify the path in the 'for' statement, like this:
for f in /some/directory/*.txt
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 04:08 PM
тАО10-13-2004 04:08 PM
Re: perl delete help
Sorry about this I have another question. Can I put this code in a .pl file:
for f in *.txt
do
'print unless(/Received:/ .. /DeliveredDate:/);' $f
done
and then run it this way:
perl -i -n -e filename.pl
I am not sure if this is legal or not.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2004 04:25 PM
тАО10-13-2004 04:25 PM
Re: perl delete help
Please disregard my previous message. I got it to work. Thank you for all your help. You saved me!