如何读取值,将其添加到第二行,然后将第二行添加到第三行,

编程入门 行业动态 更新时间:2024-10-10 23:19:39
本文介绍了如何读取值,将其添加到第二行,然后将第二行添加到第三行,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一个文件中大约有100个单元格,因此我需要读取文件名并将文件名附加到"pin",然后读取第二行并将其附加到第三行"direction",所以这是怎么回事去做

I have around 100 cells in a file so i need to read the name of the file and append the file name to "pin" then read the second line and append it to the third lines "direction" so what is the way to do it

示例

MACRO x1 PIN low { DIRECTION INPUT ; PIN high { DIRECTION INPUT ; MACRO u1 PIN S1 { DIRECTION INPUT ; PIN S2 { DIRECTION INOUT ;

我需要什么作为输出

MACRO x1 x1 PIN low x1 PIN low DIRECTION INPUT ; x1 PIN low x1 PIN low DIRECTION INPUT ; MACRO u1 u1 PIN S1 u1 PIN S1 DIRECTION INPUT ; u1 PIN S2 u1 PIN S2 DIRECTION INOUT ;

推荐答案

遵循awk可能会帮助您.

awk ' /MACRO/{ ##Looking for string MACRO here and if that is found then do following actions: val=$2; ##Creating a variable named val whose value is the 2nd field of the current line. flag=1; ##Creating a variable named flag here and setting its value to 1 here. print; ##Print is the out of the box keyword for awk and it will print the current line. next ##next is awk out of the box command which will skip all further statements. } flag && !/DIRECTION INPUT/ && NF{ ##Checking condition here if variable flag is NOT NULL and line is NOT having string DIRECTION INPUT in it and line is NOT blank: sub(/{/,""); ##Substituting character { with NULL on current line. val2=$0; ##Creating variable named val2 with value of current line. print val,$0 ##Printing the value of variable val along with current line. } /DIRECTION INPUT/{ ##Checking if current line is having string DIRECTION INPUT in it, if yes then do following: print val,val2,$0 ##Printing variable named val, val2 and current line here. } ' Input_file ##Mentioning Input_file name here.

输出如下.

MACRO XYZ XYZ PIN AB XYZ PIN AB DIRECTION INPUT ; XYZ PIN BC XYZ PIN BC DIRECTION INPUT ; MACRO GEN GEN PIN DECSEL_STG2[0] GEN PIN DECSEL_STG2[0] DIRECTION INPUT ; GEN PIN DECSEL_STG1[0] GEN PIN DECSEL_STG1[0] DIRECTION INPUT ;

更多推荐

如何读取值,将其添加到第二行,然后将第二行添加到第三行,

本文发布于:2023-11-12 11:18:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581346.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将其   到第

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!