- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: help in removing entries from 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
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
тАО09-02-2007 10:06 PM
тАО09-02-2007 10:06 PM
I could do with some help:
I have a file with a list of entries that I want to remove from a logfile:
iprange1
iprange2
iprange3
iprange4
what would be the best way to remove these from a logfile with many ipranges in?
Thanks
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2007 10:12 PM
тАО09-02-2007 10:12 PM
Re: help in removing entries from a file
something like that:
$cat logfile | grep -v ipranges > temp.file
$cat temp.file > logfile
or what syntax have your iprange?
Regards
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2007 10:17 PM
тАО09-02-2007 10:17 PM
Re: help in removing entries from a file
See also
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1156808
WK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2007 11:13 PM
тАО09-02-2007 11:13 PM
Re: help in removing entries from a file
grep -v iprange1 |grep -v iprange2 |grep -v iprange3 etc etc
is have a list of each different iprange that I do not what to display from the logfile in a file then use this to not display from the log:
ie
how do I have a file with
iprange1
iprange2
iprange3
iprange4
then not display this information from the logfile that has multiple entries of
iprange1
iprange2
iprange3
iprange4
iprange5
iprange6
iprange7
iprange8
basically the ipranges are exeptions from a report that is emailed daily.
Thanks chaps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2007 11:59 PM
тАО09-02-2007 11:59 PM
Re: help in removing entries from a file
# grep -v -f pattern_file data_file
...where 'pattern_file' contains the strings that you do *not* want to include in your output.
Please consider also evaluating your previous thread on this subject:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1156808
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 01:07 AM
тАО09-03-2007 01:07 AM
Re: help in removing entries from a file
Actually for *ranges* you have 'grep's ability to use extended regular expressions ('-E') in your pattern file ('-f)' [see the manpges for 'grep']:
For example:
# cat .pattern_file
10.11.*.2
# cat .data_file
10.11.12.1
10.11.12.2
10.11.12.3
10.11.13.1
10.11.13.2
10.11.13.3
10.11.14.1
10.11.14.2
10.11.14.3
# grep -v -E -f .pattern_file data_file
10.11.13.1
10.11.13.3
10.11.14.1
10.11.14.3
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 01:48 AM
тАО09-03-2007 01:48 AM
SolutionDISREGARD MY LAST POST! ENOCOFFEE! We need to escape the 'dot' if we want it to mean itself and not any character in the context I presented.
Actually for *ranges* you have 'grep's ability to use extended regular expressions ('-E') in your pattern file ('-f)' [see the manpges for 'grep']:
For example:
# cat .pattern_file
10\.11\.[0-9]*\.2
# cat .data_file
10.11.12.1
10.11.12.2
10.11.12.3
10.11.13.1
10.11.13.2
10.11.13.3
10.11.14.1
10.11.14.2
10.11.14.3
# grep -v -E -f ./pattern_file ./data_file
10.11.12.1
10.11.12.3
10.11.13.1
10.11.13.3
10.11.14.1
10.11.14.3
# grep -E -f ./pattern_file ./data_file
10.11.12.2
10.11.13.2
10.11.14.2
Regards!
...JRF...
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 04:46 AM
тАО09-03-2007 04:46 AM
Re: help in removing entries from a file
just as JRF remarked: make yourself clear, if you want to consider 'iprange1' as string or as pattern.
Note, that using it as pattern creates the problem, that you have to watch for wildcard characters: something like
1.2.3.4
will match
152.3.4
as well, because '.' is 'any char' when using it in regular expressions! Best use
1[.]2[.]3[.]4
for such a case.
Important as well is the fact, if your pattern are anchored at begin or end of a line. Taking this into account can speed up your script dramatically!
Second: NOT wanting a pattern match, use
fgrep (or grep -F) - this does pure string compares.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 04:59 AM
тАО09-03-2007 04:59 AM
Re: help in removing entries from a file
I am not too familiar with fgrep or egrep however do understand these are powerful tools and will check and test out.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2007 09:47 AM
тАО09-03-2007 09:47 AM
Re: help in removing entries from a file
No need to use the -E hammer, your regular expressions (*) aren't extended.
>Peter: Best use 1[.]2[.]3[.]4
Usually they are quoted with a "\".
>if your pattern are anchored at begin or end of a line. Taking this into account can speed up your script dramatically!
Right. You can do that with grep -x but the logfile could only have that number and no other data on each line.
I'm surprised Peter didn't mention the gotcha with fgrep, 1.2.3.4 will match 21.2.3.4
So you need to use grep -w, or use anchored strings in the file. Given't JRF's file:
10\.11\.[0-9]*\.2
You could use vi to add the anchors:
:%s/^/^/
:%s/$/$/