我有这样的数据:
COSM3755563_(COSMIC),_COSM3755562_(COSMIC),_rs16941_(Gene_file)
COSM148277_(COSMIC),_COSM3755561_(COSMIC),_rs16942_(Gene_file)
rs1060915_(Gene_file;_1000Genomes)
COSM3755560_(COSMIC),_rs1799966_(Gene_file)
rs206075_(Gene_file;_1000Genomes)我需要这样的输出:
rs16941
rs16942
rs1060915
rs1799966
rs206075我只需要从这个专栏中提取rs_number。问题是,rs_number总是处于不同的位置。
我的解决办法是:
awk '{split ($1,arr1,"_"); print arr1[1)}' infile在改变了我的rs_number的位置之前,这一切都很好。
感谢任何在awk方面的帮助。
发布于 2017-02-24 14:52:37
您可以使用grep来匹配线条,并且只打印匹配项,
$ grep -o "rs[[:digit:]]*" file
rs16941
rs16942
rs1060915
rs1799966
rs206075-o,-只匹配 只打印线条的匹配部分。
这也可以使用match函数在awk中完成。
$ awk '{match($0, "rs[[:digit:]]*", arr); print arr[0]}' file
rs16941
rs16942
rs1060915
rs1799966
rs206075发布于 2017-02-24 14:52:56
为此,我将使用sed:
sed 's/.*\(rs[[:digit:]]\{1,\}\).*/\1/' file搜索:
.* - any character, zero or more times
\( - begin of capturing group
rs - the literal 'rs'
[[:digit:]] - a digit ...
\{1,\} - ... one or more times (can be \+ if you use GNU sed)
\) - end of capturing group
.* - any character, zero or more times取代:
\1 - Content of capturing group 1发布于 2017-02-24 14:56:01
使用awk:
awk 'match($0, /rs[0-9]+/) { print substr( $0, RSTART, RLENGTH )}' data这不应该需要gawk,而且即使在旧的计算机上也应该工作。
https://stackoverflow.com/questions/42441557
复制相似问题