Question

I have a file words.txt in which each line is a word, followed by a TAB, followed by an integer (which represents the word's frequency). I want to generate a new file containing only those lines where the word is spelled correctly.

Using cat words.txt | hunspell -1 -G > ok_words.txt I can get a list of correct words, but how can I also include the remainder of each line (ie the TAB and the number)?

Input:

adwy  27
bird  10
cat   12
dog   42
erfgq 9
fish  2

Desired Output:

bird  10
cat   12
dog   42
fish  2
Was it helpful?

Solution

The easiest way would be to use the join command:

$ join words.txt ok_words.txt 
bird 10
cat 12
dog 42
fish 2

or to preserve tabs:

$ join -t $'\t' words.txt ok_words.txt 
bird    10
cat 12
dog 42
fish    2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top