2015-11-02 68 views
0

我试图从文本文件中的行添加到SED命令 observered_list.txt的Unix shell脚本,需要指定文本文件值sed命令

Uncaught SlingException 
cannot render resource 
IncludeTag Error 
Recursive invocation 
Reference component error 

我需要它编码如下

sed '/Uncaught SlingException\|cannot render resource\|IncludeTag Error\|Recursive invocation\|Reference component error/ d' 

帮我做到这一点。

回答

0

我建议你创建一个sed脚本和删除连续每种模式:

while read -r pattern; do 
    printf "/%s/ d;\n" "$pattern" 
done <observered_list.txt>> remove_patterns.sed 

# now invoke sed on the file you want to modify 
sed -f remove_patterns.sed file_to_clean 

另外,您可以构建sed命令是这样的:

pattern= 
while read -r line; do 
    pattern=$pattern'\|'$line 
done < observered_list.txt 
# strip of first and last \| 
pattern=${pattern#\\\|} 
pattern=${pattern%\\\|} 
printf "sed '/%s/ d'\n" "$pattern" 
# you still need to invoke the command, it's just printed 
+0

不,没有混淆,那只是一个打字错误。 – Bernhard

+0

感谢您的更新,这是我的预期,它适用于我 – thamizhinian

0

您可以使用grep为:

grep -vFf /file/with/patterns.txt /file/to/process.txt 

说明:

-v excludes lines of process.txt which match one of the patterns from output 
-F treats patterns in patterns.txt as fixed strings instead of regexes (looks like this is desired here) 
-f reads patterns from patterns.txt 

检查man grep了解更多信息。