# Comparing two lists in bash

DevFeed: [Comparing two lists in bash](<https://devfeed.tech/articles/comparing-two-lists-in-bash-27611.md>)

Original publisher: [Read original article](<https://gagor.pro/2014/02/comparing-two-lists-in-bash/>)

Author: Tom

Published: 2014-02-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Bash](<https://devfeed.tech/topics/bash.md>), [Scripting, bash](<https://devfeed.tech/topics/scripting-bash.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [compare](<https://devfeed.tech/tags/compare.md>), [linux](<https://devfeed.tech/tags/linux.md>), [search](<https://devfeed.tech/tags/search.md>)

## AI overview

This tutorial compares two Bash approaches for finding hosts present in one list but not another. It shows a filtered diff command and a grep-based command using grep -Fxv -f, followed by sorting.

## Source excerpt

I had quite simple task - compare two lists of hosts and check if hosts from first one are also on the second one. I started with diff: diff -u biglist.txt hosts_to_check.txt | grep -E "^\+" It was fine but output needs some filtering to get what I want. I've found another example with grep: grep -Fxv -f biglist.txt hosts_to_check.txt | sort -n This will search for all lines in hosts_to_check.txt which don't match any line in biglist.txt. So after this I've got list of hosts that I have to check. That's exactly what I need 😄