tcl,grep和大于号

时间:2014-03-11 22:16:46

标签: grep tcl

我正在尝试grep一个包含大于tcl的符号的字符串。 到目前为止我尝试了什么:

grep -orI -- {\> somestring} dir

但这似乎不起作用。

然后我尝试仅查找大于号:

grep -orI -- \> dir

那不起作用..

3 个答案:

答案 0 :(得分:3)

你可以做些事情来确保>不是exec cmd中单词的第一个字符:例如,使用其他不必要的捕获括号

$ tclsh
% exec cat ./afile
line1
line2 > somestring
line3
% exec grep -orI {> somestring} .
[waits for me to hit ctrl-d]
child process exited abnormally
% exec grep -orI {\(> somestring\)} .
./afile:> somestring

答案 1 :(得分:1)

我发现了这个问题和答案: how to pass command line parameter containing '<' to 'exec'

我意识到exec和>在tcl中不是朋友。我会找到一种创造性的方法来克服这个问题,或者使用其他工具来完成这项任务。

答案 2 :(得分:0)

eval是你的朋友:

set cmd "grep this someFile.txt > outputfile.txt"
eval $cmd