Operating System - HP-UX
1833315 Members
3001 Online
110051 Solutions
New Discussion

script to read values from a line

 
SOLVED
Go to solution
Theresa Patrie
Regular Advisor

script to read values from a line

Hi,
I have a netlist file that looks like this...

NET '5V' U1-2 U2-2 U5-2
NET 'GND' U4-3 U1-3 U2-3 U5-5
...
I need to read in each value and re-format so that I see...
U1-2 5V
U1-3 GND
U2-2 5V
U2-3 GND
U4-3 GND
U5-5 GND

Problem is that I do not know how many entries there will be after the signal name...could be 1 or could be 20. If I knew how many entries, it would be a no-brainer with awk. There must be a simple way to tell how many entries on a line...I am drawing a blank. Any help would be greatly appreciated!
Thanks,
Theresa
This is my easy job!
2 REPLIES 2
curt larson_1
Honored Contributor
Solution

Re: script to read values from a line

awk '{
sig = $2;
for ( i=3; i <= NF; i++ ) {
printf("%s %s\n",$i,sig);
}}' yourfile | sort

i'll leave it up to you to take care of the single quotes.
Theresa Patrie
Regular Advisor

Re: script to read values from a line

Works like a charm, Curt.
Thanks so much!
This is my easy job!