我有一个文件,其中包含文本和对环境变量的引用。例子:
#PRINTME It is always fun to start your week on a sunny ${DAY_OF_WEEK}
#PRINTME My name is ${USERNAME}, you killed my father - prepare to die!
Unrelated gibberish - not to be printed
...
将其视为元数据。
我想定义一个命令来greps这个文件并打印标记的所有内容#PRINTME
并评估环境变量。
我这样做了:grep #HELP myfile | sed "s/#PRINTME //g" | awk '{print $1}'
但我的输出是
It is always fun to start your week on a sunny ${DAY_OF_WEEK}
My name is ${USERNAME}, you killed my father - prepare to die!
代替
It is always fun to start your week on a sunny Monday
My name is Inigo Montoya, you killed my father - prepare to die!
有没有一种 SHELL 方式来做我想做的事?我正在使用TCSH
- 无法更改。grep
替换,sed
和没有问题awk
。