本文介绍了如何读取值,将其添加到第二行,然后将第二行添加到第三行,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件中大约有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 ;

这篇关于如何读取值,将其添加到第二行,然后将第二行添加到第三行,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 15:36