I have a data file, named words
, which is made of rows and 3 columns. First column is a german word, second is its translation and third some metadata like verb, noun, etc...
$ cat words
offen open verb
Fenster window noun
Regd shelf noun
To grab all the nouns I could use grep
,
$ cat words | grep noun
Fenster window noun
Regd shelf noun
I like that output because each record in its own row. The problem comes when I am trying to store that output in a variable,
$ nouns=$(cat words | grep noun)
The output now is one line where those two records merged into one,
$ echo $nouns
Fenster window noun Regd shelf noun
How can I assign a multiline output from grep
into a variable?