我正在寻找in place
命令来更改以:.:.
这
chr01 1453173 . C T 655.85 PASS . GT:AD:DP:PGT:PID 0/1:25,29:54:.:.
要
chr01 1453173 . C T 655.85 PASS . GT:AD:DP 0/1:25,29:54
简而言之,我基本上会以:PGT:PID
:.:.
和:.:.
答案 0 :(得分:1)
您正在寻找类似的内容:
sed -i.bak "/^.*:\.:\.$/ {s/:PGT:PID//g; s/:\.:\.//g;}" file
/^.*:\.:\.$/
将s命令限制为:.:.
.
需要引用的行,因为它们是正则表达式的特殊字符s
sommand用空字符串答案 1 :(得分:1)
用awk表示:
awk 'sub(/:\.:\.$/,""){sub(/:PGT:PID/,"")} 1' file
chr01 1453173 . C T 655.85 PASS . GT:AD:DP 0/1:25,29:54
使用gawk进行内部编辑,您可以添加-i inplace
选项,而只需添加> tmp && mv tmp file
即可添加<section id="pre-acquisition" class="section scrollspy" markdown="1">
content
</section>
<section id="accessioning" class="section scrollspy" markdown="1">
content
<section id="accessioning-guidelines" class="section scrollspy" markdown="1">
more content
</section>
<section id="accessioning-templates" class="section scrollspy" markdown="1">
even more content
</section>
</section>
。
答案 2 :(得分:1)
使用GNU sed和Solaris sed:
sed '/:\.:\.$/{s///;s/PGT:PID//;}' file
如果您想使用GNU sed“就地”编辑文件,请使用选项-i
。
答案 3 :(得分:1)
As a one-liner:
sed -i -e '/:\.:\.$/!n' -e 's///' -e 's/:PGT:PID//g' "$file"
Expanded:
/:\.:\.$/!n # leave lines untouched unless they end in ":.:."
s/// # replace the matched ":.:." with nothing
s/:PGT:PID//g # replace ":PGT:PID" with nothing, everywhere
We use the -i
flag to perform in-place edits. We pass each line as a separate -e
expression for portability: some sed implementations allow several commands to be concatenated with ;
, but that is not required by the POSIX standard.