awk是按行处理的

awk是按行处理的

awk ‘BEGIN{OFS=FS="\t"}{if($6=="+") {tss=$2; tss_up=tss-1000; tss_dw=tss+200;} else {tss=$3; tss_up=tss-200; tss_dw=tss+1000;} if(tss_up<0) tss_up=0;print $1, tss_up, tss_dw,$4,$5,$6;}’ test.bed > grc.bed
@@@@@@@@@@@@@本来这行只有一个符号,但是\t还是把它分割成,并且前面两个赋值了,也可以看出awk是按行处理的

yyp@xsy-TravelMate-P246M-MG:~$ cat test.bed

The MIT License

Copyright © 2017 Genome Research Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the “Software”), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in

all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

THE SOFTWARE.

Bed format information: https://genome.ucsc.edu/FAQ/FAQformat.html

X 1000 1100 X1 500 + 1000 1100 255,0,0
X 1200 1300 X2 500 + 1200 1300 255,0,0
X 1400 1500 X3 500 + 1400 1500 255,0,0
X 1600 1700 X4 500 + 1600 1700 255,0,0
X 1800 1900 X5 500 + 1800 1900 255,0,0
Y 100000 100900 Y1 600 + 100000 100900 255,0,0
Y 100200 100700 Y2 600 + 100200 100700 255,0,0
Y 100400 100500 Y3 600 + 100400 100500 255,0,0
Y 100600 100700 Y4 600 + 100600 100700 255,0,0
Y 100800 100900 Y5 600 + 100800 100900 255,0,0
Z 100000 100001 Z1 600 + 100000 100001 255,0,0
Z 100002 100003 Z2 600 + 100002 100003 255,0,0
Z 100004 100005 Z3 600 + 100004 100005 255,0,0
Z 100006 100007 Z4 600 + 100006 100007 255,0,0
Z 100008 100009 Z5 600 + 100008 100009 255,0,0

yyp@xsy-TravelMate-P246M-MG:~$ awk ‘BEGIN{OFS=FS="\t"}{if($6=="+") {tss=$2; tss_up=tss-1000; tss_dw=tss+200;} else {tss=$3; tss_up=tss-200; tss_dw=tss+1000;} if(tss_up<0) tss_up=0;print $1, tss_up, tss_dw,$4,$5,$6;}’ test.bed > grc.bed

yyp@xsy-TravelMate-P246M-MG:~$ cat grc.bed

The MIT License 0 1000

0 1000

Copyright © 2017 Genome Research Ltd. 0 1000

0 1000

Permission is hereby granted, free of charge, to any person obtaining a copy 0 1000

of this software and associated documentation files (the “Software”), to deal 0 1000

in the Software without restriction, including without limitation the rights 0 1000

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0 1000

copies of the Software, and to permit persons to whom the Software is 0 1000

furnished to do so, subject to the following conditions: 0 1000

0 1000

The above copyright notice and this permission notice shall be included in 0 1000

all copies or substantial portions of the Software. 0 1000

0 1000

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0 1000

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0 1000

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0 1000

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0 1000

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0 1000

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0 1000

THE SOFTWARE. 0 1000

0 1000

Bed format information: https://genome.ucsc.edu/FAQ/FAQformat.html 0 1000

0 1000 @@@@@@@@@@@@@本来这行只有一个符号,但是\t还是把它分割成,并且前面两个赋值了,也可以看出awk是按行处理的

X 0 1200 X1 500 +
X 200 1400 X2 500 +
X 400 1600 X3 500 +
X 600 1800 X4 500 +
X 800 2000 X5 500 +
Y 99000 100200 Y1 600 +
Y 99200 100400 Y2 600 +
Y 99400 100600 Y3 600 +
Y 99600 100800 Y4 600 +
Y 99800 101000 Y5 600 +
Z 99000 100200 Z1 600 +
Z 99002 100202 Z2 600 +
Z 99004 100204 Z3 600 +
Z 99006 100206 Z4 600 +
Z 99008 100208 Z5 600 +

发布了27 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39306047/article/details/90632921