Quantcast
Channel: User Dennis Williamson - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 61

Answer by Dennis Williamson for compare data in two files one has 2 column while other has 3 column

$
0
0

Use join, include sort if your data isn't sorted by the appropriate field.

join -1 2 -2 3 -o 2.3 <(sort -k2,2 file1) <(sort -k3,3 file2)

If sort isn't needed:

join -1 2 -2 3 -o 2.3 file1 file2

This is using GNU utilities. For other variants I would need to know what Unix you're using. The version above with sort is shown with Bash process substitution which also works in some other shells.

Since the join field is also the output field, -o 2.3 can be simplified to -o 0.


Viewing all articles
Browse latest Browse all 61

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>