- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Comparing two files in hp-ux
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
тАО02-21-2008 04:38 AM
тАО02-21-2008 04:38 AM
Comparing two files in hp-ux
I am trying to compare two files in hp-ux using diff command.
but I am not getting the proper output.
The following command I am using to find out what is in the
second file but not in the first file.
# diff file1.txt file2.txt | sed -e 's//file2content/'
Can anyone help me on this.
Is there any other command to achive the same goal?
- Tags:
- diff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 04:45 AM
тАО02-21-2008 04:45 AM
Re: Comparing two files in hp-ux
the diff does the comparation - right?
It seems, you want to something more - what?
The 'man diff' gives you options for modifying output or even (-e') generates ed-commands to create file2 from file1.
See 'man sdiff' for a side-by-sside diff.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 04:47 AM
тАО02-21-2008 04:47 AM
Re: Comparing two files in hp-ux
You probably want to use 'comm(1)'. See the manpages for more information.
Regards!
...JRF...
- Tags:
- comm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 04:48 AM
тАО02-21-2008 04:48 AM
Re: Comparing two files in hp-ux
grep -vf file1 file2
regards,
ivan
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 04:57 AM
тАО02-21-2008 04:57 AM
Re: Comparing two files in hp-ux
What is the proper output you expect?
and what output are you receiving?
and what inputs are you using?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:35 AM
тАО02-21-2008 06:35 AM
Re: Comparing two files in hp-ux
I want to find out what is the data in the first file which is not present in the second file.
Is there any way to find out?
Please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:42 AM
тАО02-21-2008 06:42 AM
Re: Comparing two files in hp-ux
sort -n file1.txt > 1
sort -n file2.tx1 > 2
diff 1 2 |grep ^"<"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:40 AM
тАО02-21-2008 07:40 AM
Re: Comparing two files in hp-ux
comm -3 file1.txt file2.txt
Provided both files are sorted.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 11:40 PM
тАО02-21-2008 11:40 PM
Re: Comparing two files in hp-ux
sort file1 -o file1.sorted
sort file2 -o file2.sorted
grep vf file1.sorted fle2.sorted
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 02:34 AM
тАО02-22-2008 02:34 AM
Re: Comparing two files in hp-ux
>harry: comm -3 file1.txt file2.txt
A slight correction, comm -13 will only print the lines from file 2.
>Arturo: sort file1 -o file1.sorted
I'm not sure why you want to sort the files unless you want to use comm(1)? You may want to use sort -u, if you don't want to see you have N lines (all the same) not in file1.
Note: Using sort (twice) and comm would be faster than grep -v, if you have 10s of thousands of lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 04:22 AM
тАО02-22-2008 04:22 AM
Re: Comparing two files in hp-ux
Example:
file1 contains a line consisting of a single '1'
Then all lines containing a '1' in file2 are skipped.
comm handles this better.
Also: mind that you want to find data in file1 that's not in file2. Meaning you want to do it the other way around: skip lines in file 1 that's not in file2.
A solution for the grep problem is to create a temporary file, containing all lines from file2 with a ^ prepended and a $ appended to each line.
Or use the -w flag for grep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 03:25 PM
тАО02-22-2008 03:25 PM
Re: Comparing two files in hp-ux
>Or use the -w flag for grep.
Oops, right. The -x flag compares the entire line. Unfortunately it still looks at patterns so you need fgrep:
fgrep -xvf file1 file2