我想运行这些sed行:
sed 's/\/1\/1/\/1/g' file -i && sed 's/\/2\/2/\/2/g' file -i
这样的文件:
chr9_paternal 126628489 126629719 616L7AAXX_HWUSI-EAS627_0005:1:1:1157:5733/1/1 0 + 126628489 126629719 255,0,0 2
19,57 0,1173
chr20_paternal 34093622 34093697 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:4527/1/1 0 + 34093622 34093697 255,0,0 1
75 0
chr17_paternal 44627748 44633513 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:5412/2/2 0 + 44627748 44633513 255,0,0 2
36,40 0,5725
chr1_paternal 224204536 224204611 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:2312/1 0 + 224204536 224204611 255,0,0 1
75 0
chr7_paternal 132309510 132309585 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:1687/2/2 0 + 132309510 132309585 255,0,0 1
75 0
chr20_paternal 45708069 45708144 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:13916/1 63 + 45708069 45708144 255,0,0 1
75 0
chr9_paternal 134850662 134850737 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:10141/1/1 72 + 134850662 134850737 255,0,0 1
75 0
chrX_paternal 71603273 71603348 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:8367/2 30 + 71603273 71603348 255,0,0 1
以获得此输出:
chr9_paternal 126628489 126629719 616L7AAXX_HWUSI-EAS627_0005:1:1:1157:5733/1 0 + 126628489 126629719 255,0,0 2
19,57 0,1173
chr20_paternal 34093622 34093697 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:4527/1 0 + 34093622 34093697 255,0,0 1
75 0
chr17_paternal 44627748 44633513 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:5412/2 0 + 44627748 44633513 255,0,0 2
36,40 0,5725
chr1_paternal 224204536 224204611 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:2312/1 0 + 224204536 224204611 255,0,0 1
75 0
chr7_paternal 132309510 132309585 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:1687/2 0 + 132309510 132309585 255,0,0 1
75 0
chr20_paternal 45708069 45708144 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:13916/1 63 + 45708069 45708144 255,0,0 1
75 0
chr9_paternal 134850662 134850737 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:10141/1 72 + 134850662 134850737 255,0,0 1
75 0
chrX_paternal 71603273 71603348 616L7AAXX_HWUSI-EAS627_0005:1:1:1158:8367/2 30 + 71603273 71603348 255,0,0 1
但文件很大,我不想读两遍。可以运行一次执行两条指令的sed代码吗?
答案 0 :(得分:6)
您可以使用-e
在一次sed
调用中执行多个表达式:
sed -e <expr> -e <expr> -i <file>
答案 1 :(得分:4)
如果我理解正确,您希望将/1/1
替换为/1
,将/2/2
替换为/2
:
sed -i 's:/1/1:/1:;s:/2/2:/2:' file
使用冒号:
代替/
,这样可以避免转义。
答案 2 :(得分:4)
在这个只需要编辑两次的示例中,您可以非常轻松地在操作之间使用-e
或分号,如其他答案所示。我在连续的行上有10个或更多-e
个选项的脚本。
如果它仍然变得更复杂(或者您需要从某些数据生成许多映射),您可以编写一个文件并让sed
从-f
选项的文件中读取其指令:< / p>
sed -f sed.script -i file