虽然读线,与多个分隔符awk的$行 [英] While read line, awk $line with multiple delimiters
问题描述
我想这,除了要告诉awk的是, :或制表\\ t时文件的定界符基于所述第五字段可以是一个冒号进行分割。我做的的awk -F'[:\\ t]'。单独
部分,它确实打印正确的$ 5外地
I am trying a small variation of this, except I telling awk that the delimiter of the file to be split based on the 5th field can either be a colon ":" or a tab \t. I do the awk -F '[:\t]'
part alone, it does indeed print the right $5 field.
然而,当我试图将其纳入更大的命令这一点,它返回以下错误:
However, when I try to incorporate this into the bigger command, it returns the following error:
print > f
awk: cmd. line:9: ^ syntax error
这是code:
awk -F '[:\t]' ' # read the list of numbers in Tile_Number_List
FNR == NR {
num[$1]
next
}
# process each line of the .BAM file
# any lines with an "unknown" $5 will be ignored
$5 in num {
f = "Alignments_" $5 ".sam" print > f
} ' Tile_Number_List.txt little.sam
为什么不将它与-F选项工作?
Why won't it work with the -F option?
推荐答案
这个问题是不是与 FS
的值,它是这条线由错误指向:
The problem isn't with the value of FS
it's this line as pointed to by the error:
f = "Alignments_" $5 ".sam" print > f
您有一条线两条语句所以无论他们分离出;
或换行符:
You have two statements on one line so either separate them with a ;
or a newline:
f = "Alignments_" $5 ".sam"; print > f
或者
f = "Alignments_" $5 ".sam"
print > f
由于采用全单行:
As full one liner:
awk -F '[:\t]' 'FNR==NR{n[$1];next}$5 in n{print > ("Alignments_"$5".sam")}'
或者作为一个脚本文件,即 script.awk
:
BEGIN {
FS="[:\t]"
}
# read the list of numbers in Tile_Number_List
FNR == NR {
num[$1]
next
}
# process each line of the .BAM file
# any lines with an "unknown" $5 will be ignored
$5 in num {
f = "Alignments_" $5 ".sam"
print > f
}
要以这种形式运行的awk -f script.awk Tile_Number_List.txt little.sam
。
编辑:
字符 -
用于从标准输入,而不是一个文件有许多的* nix工具重新present输入。
The character -
is used to represent input from stdin instead of a file with many *nix tools.
command | awk -f script.awk Tile_Number_List.txt -
这篇关于虽然读线,与多个分隔符awk的$行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!