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

AWK Formating string values to columns

Status
Not open for further replies.
Oct 11, 2002
57
AD
I have a file with this content

Parameter: NSTRBLKSCHED
Current: -
Planned: 2
Default: 2
Minimum: -
Module: -
Version: -
Dynamic: No

Parameter: NSTREVENT
Current: 50
Planned: 50
Default: 50
Minimum: -
Module: -
Version: -
Dynamic: No

and i want to assign the values after the first column to a variable and then print them into a single row, so far I could get this

cat file | grep -v "^$" | awk '
/Parameter:/ {param=$2}
/Current:/ {curr=$2}
/Planned:/ {plan=$2}
/Default:/ {def=$2}
/Minimum:/ {min=$2}
/Module:/ {mod=$2}
/Version:/ {ver=$2}
/Dynamic:/ {dyn=$2}
{ printf ( "%s %s %s %s %s %s %s %s\n",
param,curr,plan,def,min,mod,ver,dyn)
}'

but I want to avoid the repetition that I get on the output.

NSTRBLKSCHED
NSTRBLKSCHED -
NSTRBLKSCHED - 2
NSTRBLKSCHED - 2 2
NSTRBLKSCHED - 2 2 -
NSTRBLKSCHED - 2 2 - -
NSTRBLKSCHED - 2 2 - - -
NSTRBLKSCHED - 2 2 - - - No
NSTREVENT - 2 2 - - - No
NSTREVENT 50 2 2 - - - No
NSTREVENT 50 50 2 - - - No
NSTREVENT 50 50 50 - - - No
NSTREVENT 50 50 50 - - - No
NSTREVENT 50 50 50 - - - No
NSTREVENT 50 50 50 - - - No
NSTREVENT 50 50 50 - - - No


Any suggestions?

EDC
--------------------------------------
This is Unix-Land. In quiet nights, you can hear the Windows machines
reboot.
 
Something like this ?
awk '
/Parameter:/ {param=$2}
/Current:/ {curr=$2}
/Planned:/ {plan=$2}
/Default:/ {def=$2}
/Minimum:/ {min=$2}
/Module:/ {mod=$2}
/Version:/ {ver=$2}
/Dynamic:/ {dyn=$2
printf "%s %s %s %s %s %s %s %s\n",
param,curr,plan,def,min,mod,ver,dyn
}' file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Exactly!!, thanks!!



EDC
--------------------------------------
This is Unix-Land. In quiet nights, you can hear the Windows machines
reboot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top