我有一个名为“align_summary.txt”的文件,如下所示:
Left reads:
Input : 26410324
Mapped : 21366875 (80.9% of input)
of these: 451504 ( 2.1%) have multiple alignments (4372 have >20)
...more text....
... and several more lines of text....
我想在 bash shell 中提取所有左对齐读取(在本例中为 2.1)中多重对齐的百分比。
如果我使用这个:
pcregrep -M "Left reads.\n..+.\n.\s+Mapped.+.\n.\s+of these" align_summary.txt | awk -F"\\\( " '{print $2}' | awk -F"%" '{print $1}' | sed -n 4p
它立即给我输出:2.1
但是,如果我像这样用反引号括起相同的表达式:
leftmultiple=`pcregrep -M "Left reads.\n..+.\n.\s+Mapped.+.\n.\s+of these" align_summary.txt | awk -F"\\\( " '{print $2}' | awk -F"%" '{print $1}' | sed -n 4p`
我收到一个错误:
awk: syntax error in regular expression ( at
input record number 1, file
source line number 1
据我了解,将此表达式括在反引号中会影响对包含“(”符号的正则表达式的解释,尽管它已被反斜杠转义。
为什么会发生这种情况以及如何避免这种错误?
如有任何意见和建议,我将不胜感激。
非常感谢,
最佳答案
只需使用awk
:
leftmultiple=$(awk '/these:.*multiple/{sub(" ","",$2);print $2}' FS='[(%]' align_summary.txt )
关于regex - 狂欢 : regular expressions within backticks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38664253/