我有以下包含一些总线的文件:
signal_a[79:74] No No No INPUT
signal_b[83:81] No No No INPUT
signal_c[91] No No No INPUT
我想将其扩展到各个位,如下所示:
signal_a[79] No No No INPUT
signal_a[78] No No No INPUT
signal_a[76] No No No INPUT
signal_a[77] No No No INPUT
signal_a[76] No No No INPUT
signal_a[75] No No No INPUT
signal_a[74] No No No INPUT
signal_b[83] No No No INPUT
signal_b[82] No No No INPUT
signal_b[81] No No No INPUT
signal_c[91] No No No INPUT
我怎样才能用sed
或awk
或来完成它perl
?
答案1
这是相当不优雅的,但是
perl -lne '
($a,$b) = ($2 == "" ? $1 : $2,$1) if /\[(\d+)(?:\:(\d+))?\]/;
for $n (reverse $a..$b) {
print s/\[.*?\]/"[$n]"/re
}
' file
答案2
也试试
$ awk '{split ($1, T, "[][:]"); for (i=T[3]?T[3]:T[2]; i<=T[2]; i++) {$1 = T[1] "[" i "]"; print}}' OFS="\t" file3
signal_a[74] No No No INPUT
signal_a[75] No No No INPUT
signal_a[76] No No No INPUT
signal_a[77] No No No INPUT
signal_a[78] No No No INPUT
signal_a[79] No No No INPUT
signal_b[81] No No No INPUT
signal_b[82] No No No INPUT
signal_b[83] No No No INPUT
signal_c[91] No No No INPUT