Skip to content

Instantly share code, notes, and snippets.

@woshichuanqilz
Last active July 3, 2024 23:40
Show Gist options
  • Save woshichuanqilz/cd34f7f695ca48c132e00b7b2f4034e1 to your computer and use it in GitHub Desktop.
Save woshichuanqilz/cd34f7f695ca48c132e00b7b2f4034e1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# file content should be
#key:value1
#key:value2
# Read the key-value pairs from the file
data=$(cat file.txt)
# Search for a key using fzf
selected_key=$(echo "$data" | awk -F ':' '{print $1}' | fzf)
# Output the corresponding value for the selected key
selected_value=$(echo "$data" | grep "^$selected_key:" | awk -F ':' '{print $2}')
echo "Key: $selected_key, Value: $selected_value"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment