- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Filter Files..
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
тАО04-16-2008 02:09 PM
тАО04-16-2008 02:09 PM
I have 2 files, for example:
File 1:
a
b
c
d
e
File2:
b
d
The idea is to read File1 and print all lines except the strings that I have in File2. The result should be:
File3:
a
c
e
Note: The number of lines changes, isn't fix. I have to apply this rotine on oracle files, usually with more than 30000 lines and comparate with other file with 200.
I appreciate if you help in shell script.
Thank you very much
Andre
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2008 03:28 PM
тАО04-16-2008 03:28 PM
Re: Filter Files..
Assuming that the files are sorted; given your files as shown:
# comm -3 file1 file2
a
c
e
...see the manpages for 'comm'.
Regards!
...JRF...
- Tags:
- comm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2008 07:43 PM
тАО04-16-2008 07:43 PM
Re: Filter Files..
Hmmm.. this is perfect task for a SQL query!
Besides the comm solution JRF mentions,
the other classic solultion is to grep with a match file:
$ grep -v -f file2 file1
a
c
e
For this solution the files do not need to be sorted but... watch out for surprise matches as entries in file2 will be treated as regulare expressions.
I like perl solutions for this. Stick all lines from the short file in an array. The read the long file and take action based on presence in the array.
Much similar to the problem in:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1220926
Here:
$ perl -e 'open B,"
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2008 08:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2008 11:56 PM
тАО04-16-2008 11:56 PM
Re: Filter Files..
Note don't use the grep in the regular search path as it doesn't suppor the -f option.
Or use fgrep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2008 11:57 PM
тАО04-16-2008 11:57 PM
Re: Filter Files..
I'm assuming you're on HP-UX when providing the above path.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 02:24 AM
тАО04-17-2008 02:24 AM
Re: Filter Files..
O'Kevin : /usr/xpg4/bin/grep
This is the place, where SOLARIS holds its Posix-compliant commands. HP style would be, to set the environment variable UNIX95, like
UNIX95= grep ...
The remark about the different handling of the '-f' option fits to SUN as well, IMHO.
The (new) recommended call under HP-UX (>=11i) seems:
grep -F -x -f 2.txt 1.txt
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 06:17 AM
тАО04-17-2008 06:17 AM
Re: Filter Files..
Thank you very much for the suggestions, I didn't know that grep cold compare 2 files and I was trying to write a script. Your ideas simples and objective is all that I need.
Some notes, the files aren't sorted, and the path /usr/xpg4/bin don't exist. I'll use the UNIX95 variable and treat the files.
Thanks JRF, Hein, Dennis, O'Kevin and Pete.
Regards,
Andre
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 06:18 AM
тАО04-17-2008 06:18 AM
Re: Filter Files..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2008 11:27 AM
тАО04-17-2008 11:27 AM
Re: Filter Files..
It doesn't really "compare" but it filters.
>I'll use the UNIX95 variable and treat the files.
No need to use UNIX95 since the fine print only mentioned some some very minor difference dealing with -q and errors.
>O'Kevin: Note don't use the grep in the regular search path as it doesn't support the -f option.
Sure it does. You must be thinking about some foreign devil version of grep.
>Peter: The remark about the different handling of the '-f' option fits to SUN as well.
It may fit SUN but it has nothing to do with HP-UX.