Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detect the field number of a word, and print the number

Status
Not open for further replies.

menyl

Programmer
Oct 26, 2011
12
NL
Hi Guys,

I need to edit a netlist. it is a text file that contain many lines, that are dont have a certain order.
I need to find the word ( string) net. the problem is that one time it can be net01 or net56 or any other combination of the word net with any number between 0 to 1000000.
I need is to use awk to:

1. find the field number in which the word net**** appear for every
line ( might be more than one in a row)
2. insert an empty line after every line that contain net**
3. in the empty line I need to add the next string :

R_par(net** gnd) res r=1

note: if the word net** appears twice in a line, I need to add two
empty lines and each one to add the apropiate string.
the main problem is how to retrive the field number in which the word net** appear.

thanks for your help!

meny


 
awk '{print;for(i=1;i<=NF;++i)if($i~/^net[0-9]/)print "R_par("$i" gnd) res r=1"}' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you very much.

could you provide some explantions?
 
also few questions:

1. where exactly in this line it insert the empty line.
2. the new line with the new string come out :
R_par(net99) gnd) res r=1

the bracket after net99 is not need.

3. what should be the change to make if in a spacific line the word net** apear twice, and I need now two empty line, and to insert two string for each net**?

thank you so much- this was really a great help!

meny
 
Did it works for you ?
What is that you don't understand in this little program ?
 
please see my questions in the previous thread.
I think the new empy line insert is in the blank space after the second print. right?

also what I meant in section 3 is:
what should be the change to make if in a spacific line the word net** apear twice, and I need now two empty line, and to insert two string,one for each net** in a line?

thx

meny
 
1) The second print
2) The program don't add a bracket here, so the field in the input file seems to be net99) instead of net99
3) The program should do that as is

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

hold on. it works for me. it does add what it should, but look on this please ( its the output that I get):

C0 (net142 net157) mimcap l=12.0u w=12.0u m=1
R_par(net157) gnd) res r=1
C1 (net157 net142) mimcap l=12.0u w=12.0u m=1
R_par(net142) gnd) res r=1
R10 (VSS net0140) rm1 l=230n w=230n mf=(1)
R_par(net0140) gnd) res r=1
R4 (VSS net99) rm1 l=230n w=230n mf=(1)
R_par(net99) gnd) res r=1

for the first line it was supposed to add two emty lines
and in each empty line to add the R_par(net**) gnd) res r=1.
it didnt it add only one line, and add an extra bracket.

thx

meny


 
So, we have to play with the field separator:
Code:
awk 'BEGIN{FS="[ )(]+"}{print;for(i=1;i<=NF;++i)if($i~/^net[0-9]/)print "R_par("$i" gnd) res r=1"}' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Perfect!
works exactly as I need it!

Thank you so much.
just wondering- was it the FS that solved the extra bracket problem?

Thanks

meny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top