查找文件中出现的单词的所有实例

使用bash我想知道如何find以文本开头的单词的所有实例,将其作为variables存储并打印出来。

例如,如果这是我的文件

test.conf

$temp_test test $1234_$temp $temp_234 

我的输出如下:

  $temp_test $temp_234 

谁能告诉我这可能是怎么回事? 这是迄今为止我能得到的最接近的。

 while read NAME do echo "$NAME" done < test.conf 

你可以用正确的正则表达式来使用grep:

 grep '^ *$temp' test.conf $temp_test $temp_234 

更新:根据意见:

 while read -rl; do echo "$l" done < <(sed -n '/^ *$temp_/s/^ *\$temp_//p' t.conf) test 234