- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Perl: How to delete a paragraph fromtext file
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
тАО06-01-2007 03:54 AM
тАО06-01-2007 03:54 AM
Example:
file.txt
1. This forum is for discussing both general and technical issues regarding Linux OS.TXT distributions running on or utilizing Hewlett-Packard products.
2. forum is for discussing both general and technical issues regarding Linux OS distributions running on or utilizing Hewlett-Packard products.
3. The forum is for discussing both general and technical issues regarding Linux OS distributions running on or utilizing Hewlett-Packard products.TXT
If any line contain .TXT I want to delete that paragraph and print the remaining paragraph to newfile.txt
from above newfile.txt should only have (prag 2.)
while (<>) {
print unless m/\b.TXT/i;
not working.
-JC.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2007 08:08 AM
тАО06-01-2007 08:08 AM
Re: Perl: How to delete a paragraph fromtext file
# perl -nle 'BEGIN{$/=""};next if m{\.TXT};print' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2007 08:41 AM
тАО06-01-2007 08:41 AM
Re: Perl: How to delete a paragraph fromtext file
Thanks for the reply.
I'm not sure how do I open/read the file, and then apply perl -nle 'BEGIN{$/=""};next if m{\.TXT};print' file
Thanks,
-JC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2007 08:51 AM
тАО06-01-2007 08:51 AM
Solutionmay be this script can solve your problem?
----file.pl----
#!/usr/bin/perl -w
open (LIST,"file.txt") || die "where is file?\n";
$^I = '';
$/ = '';
while (
- ) {
next if /^.*\.TXT.*\n/;
print;
}
close (LIST);
--------------
# ./file.pl > newfile.txt
BR
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2007 03:41 AM
тАО06-02-2007 03:41 AM
Re: Perl: How to delete a paragraph fromtext file
> I'm not sure how do I open/read the file, and then apply perl -nle 'BEGIN{$/=""};next if m{\.TXT};print' file
Well, my command-line script did it all for you. Adding your requirement for case-insensitive matching and a boundry (\b):
# perl -nle 'BEGIN{$/=""};next if m{\b\.TXT}i;print' file
Simply paste the line above and substitute the name of your 'file' for 'file', or drop the 'file' argument and pipe an output stream to Perl.
Notice that a "." signifies any character unless escaped.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2007 08:04 AM
тАО06-04-2007 08:04 AM