- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Comparing Two Text 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
Forums
Discussions
Discussions
Discussions
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
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
03-04-2009 02:03 PM
03-04-2009 02:03 PM
I have 3 text files named by s_list, s_list_new and dmg_file. where I have to compare s_list and s_list_new and whatever the unique values are in s_list I have to add that in the dmg_file. And the values they are only in s_list_new and not in s_list I have to delete that from dmg_file
I have tried so many things, but diff, comm is not helping me because if i do comm it compares line by line and the value may not match line by line and with diff its not giving me exact output and I am thinking may be im not aware of different diff output formats.
for example if i do diff temp temp1 i get like this output and I dont want it. i just want thos unique values nothing else
diff temp temp1
1,5d0
< a
< 1
< 2
< 3
< 4
11c6,9
<
---
> 10
> 11
> 12
> 13
Any Help Plz
I will appreciate the help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2009 02:13 PM
03-04-2009 02:13 PM
Re: Comparing Two Text Files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2009 02:14 PM
03-04-2009 02:14 PM
Re: Comparing Two Text Files
You might find:
# diff -c file1 file2
...quite useful. See the manpages for 'diff'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2009 03:24 PM
03-04-2009 03:24 PM
Re: Comparing Two Text Files
grep -vf file1 file2
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2009 10:23 PM
03-04-2009 10:23 PM
Solution# sort for comm
sort s_list > s_list.s
sort s_list_new > s_list_new.s
# add unique stuff to dmg_file
comm -23 s_list.s s_list_new.s >> dmg_file
# get unique stuff to remove
comm -13 s_list.s s_list_new.s > dmg_file.r
# sort for comm
sort dmg_file > dmg_file.s
# Remove stuff that was in s_list_new
comm -13 dmg_file.r dmg_file.s > dmg_file
# cleanup
rm -f s_list.s s_list_new.s dmg_file.[rs]
>Ivan: grep -vf file1 file2
Caution about grep, you need to use -x and may need fgrep instead if comparing whole lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 07:26 AM
03-05-2009 07:26 AM
Re: Comparing Two Text Files
You can do this with a combination of commands "diff" and "comm". Please see the man page for both.
Good luck
Shahul