gendict - Linux


gendict is a command-line utility used to create a dictionary or hash table from a list of input values. It is commonly employed to facilitate quick and efficient lookups in various programming contexts.


gendict [OPTIONS] [VALUE [VALUE ...] ]


  • -h, –help: Display help message
  • -f, –file FILE: Read values from the specified file
  • -s, –separator SEPARATOR: Specify the input value separator (default: whitespace)
  • -k, –key-value: Treat each input value as a key-value pair (default: false)
  • -o, –output FILE: Write the generated dictionary to the specified file (default: stdout)


Example 1: Create a dictionary from a list of strings

gendict "apple" "banana" "cherry"

Example 2: Create a key-value dictionary from a text file

gendict -k -f values.txt

Example 3: Save the dictionary to a file

gendict -k -o dictionary.txt

Common Issues

  • Incorrect Separator: Ensure that the specified separator aligns with the input format.
  • Invalid Key-Value Pairs: When using the -k option, make sure each input value follows the key=value syntax.
  • Duplicate Keys: Using the -k option, duplicate keys will overwrite existing values in the dictionary.


gendict can be integrated with other Linux commands to perform complex tasks, such as:

cat values.txt | gendict -f - | sort

This command reads values from values.txt, generates a dictionary using gendict, and sorts the dictionary by its keys.

Related Commands

  • sort: Sort text input
  • uniq: Remove duplicate lines from a file
  • join: Merge files based on common fields