gpt4 book ai didi

awk - 引用字段并为该字段分配一些逻辑

转载 作者:行者123 更新时间:2023-12-04 03:48:25 25 4
gpt4 key购买 nike

我有一个包含数据的输入文件

cell   input     out    type      fun            level
AI20 A1,A2,A3 Z comb ((A1A2)) 2
INV I1 ZN comb (!I1) 1
BUF A1,A2,A3,B1 Z comb (!(((A1A2)A3)B1)) 4
CLK C Z seq Cq 1
XOR A1,A2,B1 Z comb (((A1A2)B1) 3
IAD A1,A2,A3 Z comb (!((A1A2)A3)) 3
INV I1 ZN comb (!I1) 1

我想要如下输出

cell   ins    input                             out
AI20 i1 .A1(A),.A2(B),.A3(C) .Z(n1)
INV i2 .I1(n1) .ZN(n2)
BUF i3 .A1(n2),.A2(1),.A3(0),.B1(0) .Z(n3)
CLK i4 .C(n3) .Z(n4)
XOR i5 .A1(n4),.A2(0),.B1(0) .Z(n5)
IAD i6 .A1(1),.A2(n5),.A3(0) .Z(n6)
INV i7 .I1(n6) .ZN(X)

逻辑是

if it is first line of input file I.e AI20 assign its inputs A1,A2 to user defined A and B and assign it output to n1. For next line in input file assign previous net n1 to one of input and 0/1 to other inputs of that line and assign its output to next net n2 and so on. n1, n2,n3 so on are nets and can be assigned to an array which has no. Of rows equal to no of rows in (input file)-1(no. of rows exclude header row of input file). If it is last line or row of input file then assign that line or row output to X.i1,i2,i3... are instance name which has number of rows equal to no of rows of (input file).

A,B,X are user defined. We can directly use them in code. The term inside bracket for input is basically the one present in the previous line in output(). Exception will be for first line input and last line output whose () terms are directly defined.

我用代码

awk ' { print $1 ;print "."$2"()"; print "."$3"()" file }'

这给了我,但我如何为 inside() 构建逻辑。

AI20   .A1(), .A2(),.A3()    .Z()    

最佳答案

你可以使用这个 awk 脚本:

cat remap.awk

NR == 1 {
print "cell ins input out"
next
}
id != "" {
++r
print id, "i" r, s, "." out "(n" r ")"
}
{
n = split($2, a, /,/)
s = ""
if (NR == 2) {
ch = 65
for (i=1; i<=n; ++i)
s = (s == "" ? "" : s ",") sprintf(".%s(%c)", a[i], ch++)
} else {
s = "." a[1] "(n" r ")"
for (i=2; i<=n; ++i)
s = s "," sprintf(".%s(%d)", a[i], i%2)
}

id = $1
out = $3
}
END {
if (r)
print id, "i" r+1, s, "." out "(X)"
}

然后将其用作:

awk -f remap.awk file.txt | column -t

cell ins input out
AI20 i1 .A1(A),.A2(B),.A3(C) .Z(n1)
INV i2 .I1(n1) .ZN(n2)
BUF i3 .A1(n2),.A2(0),.A3(1),.B1(0) .Z(n3)
CLK i4 .C(n3) .Z(n4)
XOR i5 .A1(n4),.A2(0),.B1(1) .Z(n5)
IAD i6 .A1(n5),.A2(0),.A3(1) .Z(n6)
INV i7 .I1(n6) .ZN(X)

关于awk - 引用字段并为该字段分配一些逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64769056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com