如何在替换期间在for循环中添加条件

时间:2016-02-15 01:32:36

标签: bash unix awk

我正在尝试在此代码中添加一个条件,例如,如果字符串或repl [string]的转换文件中有空字符串,则我的文件input_chk.txt具有以下详细信息:

input_chk.txt

    b73_chr10   w22_chr2
    w22_chr7    w22_chr10
    w22_chr8

代码:

#!/usr/bin/awk -f
# Collect the translations from the first file.
NR==FNR { repl[$1]=$2; next }

# Step through the input file, replacing as required.
{
if 
for ( string in repl ) {
if (length(string)==0)
{
    echo "error"
}
else
{
sub(string, repl[string])
}
}
#if string is null-character,then we have to add rules,
#if repl[string] is null-character,then we have to delete rules or put # in front of all lines until we reach </rules> also
# And print.
1

# to run this script as $ ./bash_script.sh input_chk.txt file.conf

file.conf

<rules>
<rule>
condition =between(b73_chr10,w22_chr1)
color = ylgn-9-seq-7
flow=continue
z=9
</rule>
<rule>
condition =between(w22_chr7,w22_chr2)
color = blue
flow=continue
z=10
</rule>
<rule>
condition =between(w22_chr8,w22_chr3)
color = vvdblue
flow=continue
z=11
</rule>
</rules>

但是,我的代码在第8行显示错误。如何包含条件,以便在第一列或第二列中缺少字符串时可以打印错误。

0 个答案:

没有答案