- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to remove content in a 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
тАО08-28-2007 10:55 PM
тАО08-28-2007 10:55 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2007 11:01 PM
тАО08-28-2007 11:01 PM
Re: how to remove content in a file
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2007 11:02 PM
тАО08-28-2007 11:02 PM
Re: how to remove content in a file
ex.
cat file1 | grep "^Error" >file2
Marcin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2007 11:28 PM
тАО08-28-2007 11:28 PM
Re: how to remove content in a file
Using 'grep' is certainly one way to do this. As shown by Marcin, you probably want to anchor your match to the beginning of the line since you said '...except lines [that begin with] the word "Error"'.
It is wasteful to 'cat' the file into a pipe to 'grep'. That adds another process!
You could also use Perl and to select lines beginning with "Error" and having a word-boundry on either side (\b).
# perl -ne 'print if /\bError\b/' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 12:12 AM
тАО08-29-2007 12:12 AM
Re: how to remove content in a file
Of course all above methods are correct, but I check speed of processing those three methods. If you interested in
1. only grep
2. cat+grep
3. perl
on file with 4M lines, result was:
1. 4.1s
2. 4.5s
3. 9.5s
Marcin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 12:49 AM
тАО08-29-2007 12:49 AM
Re: how to remove content in a file
Please be VERY explicit about 'Error'.
Spelled EXACTLY so, or more upper/lower combinations
Exactly in the beginning of the line, or 'close' (how close!).
Or are you looking for 'Error' anywhere as seperate word(the first perl solution)?
Marcin,
Whiel you are trying... please re-try perl again with an anchorred RE where it does not have to scan the whole line:
# perl -ne 'print if /^Error/' file
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 12:54 AM
тАО08-29-2007 12:54 AM
Re: how to remove content in a file
Ooops, thanks Hein, I beat the anchor drum and then mistyped myself :-{
Also, while I would expect Perl to have a small startup overhead, its value in cases like this lies in its superior regular expression engine.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 01:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 02:51 AM
тАО08-29-2007 02:51 AM
Re: how to remove content in a file
even shorter as Sandman's solution:
awk '/^Error/' file
or taking '"Error" is the first word' into account:
awk '$1=="Error"' file
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 07:33 PM
тАО08-29-2007 07:33 PM
Re: how to remove content in a file
sed -n '/^Error/p' file
HTH,
Art