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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric Search

Status
Not open for further replies.

whitts01

Technical User
Jan 24, 2006
18
0
0
GB
Help ....

New to awk & finding it instance headache material ... I am almost there just can't get the last bit.
I will have the following into :

Product Name: CATIA MECH V4 ADD Workstations

Concurrent Offline Soft-Stop Queued
Licenses In-Use In-Use In-Use Not In-Use Requests
-------- ---------- ----------- ---------- ---------- ----------
25 15.00 0.00 0.00 10.00 0

Out of this file I want to pull Product name followed by licenses / In-Use / Not In-Use. This isn't a problem just can't find the command to extract the numbers as we will have lots of different amounts of licenses. What I want is to print out the line that starts with a number. So the output would look like :

Product Name: CATIA MECH V4 ADD Workstations
Licenses In-Use Not In-Use
25 15.00 10.00

Hope this makes sense

Thanks
 
What have you tried so far and where are you stuck in your code ?

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

Got it working but one problem ... Script as follows :

awk '/Product Name:/' /BACKUP/scripts/lics/output
awk '/Licenses/ {print $1 " "$2" " $5" " $6}' /BACKUP/scr
ipts/lics/output
awk '{if ($1 >= "0" && $1 <= "9999" ) print $1," " $2,"
" $5 }' /BACKUP/scripts/lics/output

This gives me the output I am after but when I run it against the output file with multiple license usage in I get the following :

All the Product names followed by
License line followed by
License numbers

eg :
Product Name: LicensePower/iFOR Test Product
Product Name: MD2-Catia Mechanical Design C2
Product Name: Multi-axis Machining Add-on
Product Name: N3G-ENOVIA 3D Com Navigator Con
Product Name: PROCADAM Access: IUE
Product Name: PROCADAM Interact. Design
Product Name: S3P-ENOVIA 3D Com Space Anal
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
Licenses In-Use Not In-Use
1 0.00 1.00
25 8.00 17.00
1 0.00 1.00
1 0.00 1.00
4 1.00 3.00
2 0.00 2.00
1 0.00 1.00

How do I change this script to keep all the information together.

eg
Product Name: LicensePower/iFOR Test Product
Licenses In-Use Not In-Use
1 0.00 1.00

Then the next set of license info .. etc etc


Make any sense




 
Use a single awk program:
awk '
/Product Name:/ {print}
/Licenses/ {print $1 " "$2" " $5" " $6}
$1~/^[0-9]/ {print $1," " $2," " $5 }
' /BACKUP/scripts/lics/output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Just the job .... one last question how do you go about putting a blank line after the license numbers & the next product name.

Thanks again
 
Manged to sort out the Blank line ("\n") but wondering how easy it would be to tidy the numbers ...


From this:

Product Name: LicensePower/iFOR Test Product
Licenses In-Use Not In-Use
1 0.00 1.00

To This : E.g Get rid off the .00 after the number


Product Name: LicensePower/iFOR Test Product
Licenses In-Use Not In-Use
1 0 1

Thanks
 
In the awk man page look at the printf function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[tt]
Perhaps something like ...

$0 ~/Product Name:/ { print $0 }

$0 ~/Lic/ {
AA=sprintf("%s", substr($0,1,10))
BB=sprintf("%s", substr($0,11,9))
EE=sprintf("%s", substr($0,50,12))
}

$0 ~/[0-9]/ {
A1=sprintf("%s", substr($0,1,10))
B2=sprintf("%s", substr($0,11,8))
E3=sprintf("%s", substr($0,50,8))
}

END {
print AA BB EE
print A1 B2 E3
}

$awk -f script.awk data| sed 's/\.00/ /g'
Product Name: CATIA MECH V4 ADD Workstations
Licenses In-Use Not In-Use
25 15 10
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top