Skip to content

Instantly share code, notes, and snippets.

@ironiridis
Created May 7, 2023 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironiridis/88307a682fdf9dec4f83a5c09ff2725a to your computer and use it in GitHub Desktop.
Save ironiridis/88307a682fdf9dec4f83a5c09ff2725a to your computer and use it in GitHub Desktop.
Thesaurus words without 'e'
# outputs the original line with all commas intact, where any column with 'e' is empty
awk 'BEGIN {FS=","; OFS=","} { for(x=2;x<=NF;x++) { if(index($x, "e") != 0) {$x=""} } print $0 }'
# outputs the condensed version with no extra empty fields
jq -Rr 'rtrimstr("\r")|rtrimstr("\n")|split(",") | [(.[0])] + ((. - [.[0]]) | map(select(test("e")==false))) | join(",")'
# -R ingests the input as raw lines of text, rather than json
# -r outputs raw lines of text
# rtrimstr("\r")|rtrimstr("\n") -- removes line endings from the input string, which jq includes with -R
# split(",") -- creates an array split on commas
# [(.[0])] -- creates a single-element array consisting of the first element; here, just the head word
# (. - [.[0]]) -- creates an array that is the input array subtracting the first element; here, just the synonyms
# map(select(test("e")==false)) -- filters the elements of the array and returns only elements without "e"
# [(.[0])] + ((. - [.[0]]) | map(select(test("e")==false))) -- create a new array of the head word followed by synonyms, if any
# join(",") -- create a comma-delimited result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment