Skip to content

Instantly share code, notes, and snippets.

@jesugmz
Last active February 25, 2019 00:22
Show Gist options
  • Save jesugmz/5c1b2f1903c2dd180a179763f1d8c2d8 to your computer and use it in GitHub Desktop.
Save jesugmz/5c1b2f1903c2dd180a179763f1d8c2d8 to your computer and use it in GitHub Desktop.
Extract unique values using Bash

Extract unique values using Bash

awk

Usage

[command with duplicate output |] awk '!a[$0]++' [filename with duplicate values]

Examples

cat file_with_duplicate_values.txt | awk '!a[$0]++'

awk '!a[$0]++' file_with_duplicate_values.txt

sort & unique pipes

Usage

<command with duplicate output> | sort | unique

Example

cat file_with_duplicate_values.txt | sort | unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment