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!

Two Lines Output to One Line 1

Status
Not open for further replies.

imFrank

Technical User
Mar 30, 2005
28
US
NEED HELP CHANGING FORMAT OF OUTPUT FROM TWO LINES FOR EACH BLOCK OF DATA READ TO ONE LINE OF OUTPUT. Using C-Shell

THIS IS WHAT I GET: OUTPUT IS SPLIT INTO TWO LINES
ws8 94% awk -f /usr/tmp/get_par.awk DATA.par
AS HARDDEF
SPAR VEH ALARM HEARTBEAT
AS COMMAND
SPAR VEH ALARM HEARTBEAT
RV HARDDEF
SPAR VEH ALARM HEARTBEAT

THIS IS WHAT I WANT:
AS HARDDEF SPAR VEH ALARM HEARTBEAT
AS COMMAND SPAR VEH ALARM HEARTBEAT
RV HARDDEF SPAR VEH ALARM HEARTBEAT

ws8 95% cat /usr/tmp/get_par.awk
/@NAME:/ {print (substr($0,8,2)) " " (substr($0,35,7))};
{if (/@DESC:/) {print substr($0,8,25)} }

SAMPLE DATA
ws8 96% cat DATA.par
@VERSION_NUM: 1.13

@JITTER_VAL: 15 @MATH_TRIG:

@NAME: ASALARM_HB @STREAM: HARDDEF
@DESC: SPAR VEH ALARM HEARTBEAT @UNITS: BI-LVL
@DATAQ_CC
@ENABLE_LIMITS: NO
@PROC_LOC: FRONT END @FEND_NO: 1 @TIME_FMT: BINARY
@RAW_COMP: NONE
@RAW_CONV: IEEE FP
@EU_CAL: NULL
@EU_COMP: NONE
@YEL_LO: -9.8e+05 @YEL_HI: 9.8e+05 @RED_LO: -9.8e+05 @RED_HI: 9.8e+05
@DYN_LIMS: INACTIVE
@FMT: FLOAT @RES: 3

@NAME: ASALARM_HBT_CS @STREAM: COMMAND
@DESC: SPAR VEH ALARM HEARTBEAT ENABLE CMD ST @UNITS: CMD ST
@DATAQ_CC
@EU_CAL: NULL
@FMT: FLOAT @RES: 3

@NAME: RVALARM_HBT_SS @STREAM: HARDDEF
@DESC: SPAR VEH ALARM HEARTBEAT SCRIPT STATUS @UNITS: DSCRTE
@DATAQ_CC
@ENABLE_LIMITS: NO
@PROC_LOC: FRONT END @FEND_NO: 1 @TIME_FMT: BINARY
@RAW_COMP: NONE
@RAW_CONV: IEEE FP
@EU_CAL: NULL
@EU_COMP: NONE
@YEL_LO: -9.8e+05 @YEL_HI: 9.8e+05 @RED_LO: -9.8e+05 @RED_HI: 9.8e+05
@DYN_LIMS: INACTIVE
@FMT: FLOAT @RES: 3


 
/@NAME:/ {printf "%s %s ",substr($0,8,2),substr($0,35,7)}
/@DESC:/ {print substr($0,8,25)}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
BEGIN{FS=" *[@:] *"; ORS=""}
"NAME"==$2 { print $3 OFS }
"DESC"==$2 { print $3 RS }
 
futurelet,

I've discovered with your code, the original substr I wrote left off the tail end of @DESC: data. I've corrected that mistake.

In the @NAME: field, I only wanted to see the first three characters following @NAME:, plus I wanted to see the value following @STREAM:. I've modified the code as follows:
BEGIN{FS=" *[@:] *"; ORS=" "}
"NAME"==$2 { print substr($3,1,3) OFS $5}
"DESC"==$2 { print $3 RS }

Running the modified script gives me the following results:
ASA HARDDEF SPAR VEH ALARM HEARTBEAT
ASA COMMAND SPAR VEH ALARM HEARTBEAT ENABLE CMD ST
RVA HARDDEF SPAR VEH ALARM HEARTBEAT SCRIPT STATUS

For aesthetics, I've defined ORS to contain two (2) spaces. But as you can see from my output, all the data after the first line contains the two spaces at the beginning of each new line. Can you help me eliminate the leading spaces?
 
BEGIN{FS=" *[@:] *"}
"NAME"==$2 { printf "%s %s ",substr($3,1,3),$5}
"DESC"==$2 { print $3 }

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
BEGIN { FS=" *[@:] *" ; ORS="" }
"NAME"==$2 { print substr($3,1,3) OFS $5 "  " }
"DESC"==$2 { print $3 RS }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top