In response to this post.
Created
May 7, 2023 16:36
-
-
Save ironiridis/88307a682fdf9dec4f83a5c09ff2725a to your computer and use it in GitHub Desktop.
Thesaurus words without 'e'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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