- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: To remove lines using perl
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
Forums
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
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
тАО12-09-2010 12:15 AM
тАО12-09-2010 12:15 AM
To remove lines using perl
I am trying to remove line from a while when i have search for a particular sting.
i.e.
&123&123&12314215&&abc123
&123&123&12314215&hour&abc112
&123&123&12314215&&abc115
&123&123&12314215&hour&abc113
&123&123&12314215&&abc115
&123&123&12314215&&abc115
i would want to remove the lines which contains the whole string which contains hour and the results would be
&123&123&12314215&&abc123
&123&123&12314215&&abc115
&123&123&12314215&&abc115
&123&123&12314215&&abc115
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2010 04:45 AM
тАО12-09-2010 04:45 AM
Re: To remove lines using perl
# perl -ne 'print unless /&hour/' file
...or in a 'while' loop:
# perl -e 'while (<>) {print unless /&hour/}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2010 07:30 AM
тАО12-09-2010 07:30 AM
Re: To remove lines using perl
$ perl -ne'/&hour/ or print' file.dta
is fine, it is much easier with grep
$ fgrep -v '&hour' file.dta
There is a right tool for every problem. In many an occasion that would be perl, but imho, here it is not
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2010 08:13 AM
тАО12-09-2010 08:13 AM
Re: To remove lines using perl
Both previous posts are correct. I would probably use perl if I wanted to change original file or a 'grep -v' if I was piping the output to something else.
perl -i -nle 'print unless (/&hour/)' ${file}
would edit the file in place.
grep -v '&hour' | while IFS=& read ...
if you were going to do something with the output...
That's the nice thing about UNIX; there's usually several 'right' answers - just depends on what you want to do.
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2010 02:05 PM
тАО12-09-2010 02:05 PM
Re: To remove lines using perl
It occurs to me (since you problem description is so nebulous and abstract) that perhaps you want to perform some processing in the loop but skip over some records:
...
while (<>) {
...
next if /&hour/; # resume reading next record, if any
...
}
Regards!
...JRF...