LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-14-2012, 04:25 AM   #1
rene21976
LQ Newbie
 
Registered: Mar 2011
Posts: 8

Rep: Reputation: 0
getting multiple lines into one


Hi all,

I'm trying to get output of a command into readable output. Now my output looks like this:

NAME=rg1.lsnr_pver
TYPE=application
LAST_SERVER=slssc001
STATE=ONLINE on slssc001
TARGET=ONLINE
CARDINALITY_ID=1
CREATION_SEED=145
RESTART_COUNT=0
FAILURE_COUNT=0
FAILURE_HISTORY=
ID=rg1.lsnr_pver 1 1
INCARNATION=7
LAST_RESTART=02/09/2012 23:43:15
LAST_STATE_CHANGE=02/22/2012 20:58:58
STATE_DETAILS=
INTERNAL_STATE=STABLE

NAME=rg1.lsnr_pvgi
TYPE=application
LAST_SERVER=slssc001
STATE=ONLINE on slssc001
TARGET=ONLINE
CARDINALITY_ID=1
CREATION_SEED=181
RESTART_COUNT=0
FAILURE_COUNT=0
FAILURE_HISTORY=
ID=rg1.lsnr_pvgi 1 1
INCARNATION=7
LAST_RESTART=02/09/2012 23:43:22
LAST_STATE_CHANGE=02/22/2012 20:58:58
STATE_DETAILS=
INTERNAL_STATE=STABLE

NAME=rg1.lsnr_pwro
TYPE=application
LAST_SERVER=slssc001
STATE=ONLINE on slssc001
TARGET=ONLINE
CARDINALITY_ID=1
CREATION_SEED=147
RESTART_COUNT=0
FAILURE_COUNT=0
FAILURE_HISTORY=
ID=rg1.lsnr_pwro 1 1
INCARNATION=6
LAST_RESTART=02/09/2012 22:56:26
LAST_STATE_CHANGE=02/22/2012 20:58:58
STATE_DETAILS=
INTERNAL_STATE=STABLE

What I want is that the info of 1 section is printed on one line. Please give me some hints how to do.

Thanks in advance for all the help!
 
Old 03-14-2012, 05:15 AM   #2
rene21976
LQ Newbie
 
Registered: Mar 2011
Posts: 8

Original Poster
Rep: Reputation: 0
some extra info, I would like the output looks like this :

NAME TYPE LAST_SERVER STATE TARGET etc
------------- ------------ ------------ ----------------- ---------- etc
rg1.lsnr_pver application slssc001 ONLINE on slssc001 ONLINE etc
rg1.lsnr_pvgi application slssc001 ONLINE on slssc001 ONLINE etc
 
Old 03-14-2012, 06:27 AM   #3
adixon
Member
 
Registered: Oct 2010
Posts: 34

Rep: Reputation: 3
Hi rene,
Complicated solution: grep by different patterns to numcols temp files
ie grep 'NAME=' input.txt 1>out1.txt
then custom c code to read one line of each input file and print to stdout

Warning there must be better solutions..
 
Old 03-14-2012, 07:13 AM   #4
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

This may work, but depends on assumption that keys are in the same order:
Code:
$ awk -F= '$1{tab[++c]=$2} !$1 && c>0 {OFS="\t"; for (i=1; i<=c; i++) $i=tab[i];  print; split("", tab); c=0}' infile.txt 
rg1.lsnr_pver   application     slssc001        ONLINE on slssc001      ONLINE  1       145     0       0               rg1.lsnr_pver 1 1       7    02/09/2012 23:43:15      02/22/2012 20:58:58             STABLE
rg1.lsnr_pvgi   application     slssc001        ONLINE on slssc001      ONLINE  1       181     0       0               rg1.lsnr_pvgi 1 1       7    02/09/2012 23:43:22      02/22/2012 20:58:58             STABLE
Fields in resulting array are delimited by tabs (so that empty entries or entries with spaces do not lost) so there should be no tabs after = in input.

EDIT: Last input line should be empty for last entry to be printed.

Last edited by firstfire; 03-14-2012 at 07:40 AM.
 
Old 03-14-2012, 10:29 AM   #5
rene21976
LQ Newbie
 
Registered: Mar 2011
Posts: 8

Original Poster
Rep: Reputation: 0
thanks for the input, got some script which is working

format_crs_status_resource='
BEGIN {
FS="=";
ittype=empty
}
{
if ( $1 == "NAME") {
tname=$2
tx=split( $2, tsplit, "_")
tabrev=tsplit[tx]
ttype="unknown"
if ( tabrev == "asm" )
ttype="ASM"
if ( tabrev == "lsnr" )
ttype="Listener"
if ( tabrev == "db" )
ttype="Database"
if ( tabrev == "inst" )
ttype="Instance"
if ( tabrev == "vip" )
ttype="Virtual IP"
if ( tabrev == "ons" )
ttype="Ora Notif Svc"
if ( tabrev == "cs" )
ttype="Service"
if ( tabrev == "srv" )
ttype="Service"
}
if ( $1 == "TYPE") {
ottype=$2
if (ottype == "application") {
ottype=ttype
ittype=empty
}
else {
tx=split( $2, tsplit, ".")
ittype=tsplit[2]
if ( ittype == "asm" )
ottype="ASM"
else if ( ittype == "gsd" )
ottype="Gbl Svc Daemon"
else if ( ittype == "listener" )
ottype="Listener"
else if ( ittype == "scan_listener" )
ottype="SCAN Listener"
else if ( ittype == "scan_vip" )
ottype="SCAN VIP"
else if ( ittype == "oc4j" )
ottype="OC4J"
else if ( ittype == "eons" )
ottype="eons"
else if ( ittype == "ons" )
ottype="Ora Notif Svc"
else if ( ittype == "network" )
ottype="Network (VIP)"
else if ( ittype == "cluster_vip_net1" )
ottype="Cluster VIP"
else ottype=ittype
}
}
if ( $1 == "TARGET") {
ttarget=$2
tx=split( $2, targetsplit, ",")
}
if ( $1 == "STATE") {
if ( ittype == "asm" || ittype == "ons" || ittype == "eons" || ittype == "network" || ittype == "listener" ) {
stx=split( $2, statesplit, ",")
}
else {
tx=split( $2, tsplit, " ")
tstate=tsplit[1]
tnode=tsplit[3]
}
}
if ( $1 == "RESTART_COUNT") {
trestart_count=$2
tx=split( $2, restart_countsplit, ",")
}
if ( $1 == "LAST_RESTART") {
tlast_restart=$2
tx=split( $2, last_restartsplit, ",")
}
if ( $1 == "STATE_DETAILS") {
tdetail=$2
if ( ittype == "asm" || ittype == "ons" || ittype == "eons" || ittype == "network" || ittype == "listener" ) {
for (i in statesplit) {
tx=split( statesplit[i], tsplit, " ")
tstate=tsplit[1]
tnode=tsplit[3]
ttarget=targetsplit[i]
gsub(/ */,"",ttarget)
gsub(/ */,"",tstate)
if ( ttarget == "ONLINE" && tstate != "ONLINE" )
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s %s\n", tname, ottype, ttarget, tstate, tnode, trestart_count, tlast_restart, tdetail)
else
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s %s\n", tname, ottype, ttarget, tstate, tnode, trestart_count, tlast_restart, tdetail)
}
}
else {
if ( ttarget == "ONLINE" && tstate != "ONLINE" )
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s %s\n", tname, ottype, ttarget, tstate, tnode, trestart_count, tlast_restart, tdetail)
else
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s %s\n", tname, ottype, ttarget, tstate, tnode, trestart_count, tlast_restart, tdetail)
}
}
}'
# End of variable: format_crs_status_resource

format_crs_stat='
{
if ($1 == "NAME") {
tname=$2
}
if ($1 == "TYPE") {
ttype=$2
}
if ($1 == "TARGET") {
ttarget=$2
}
if ($1 == "RESTART_COUNT") {
trestart_count=$2
}
if ($1 == "LAST_RESTART") {
tlast_restart=$2
}
if ($1 == "STATE") {
split( $2, tsplit, " ")
tstate=tsplit[1]
tnode=tsplit[3]
if ( ttarget == "ONLINE" && tstate != "ONLINE" )
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s\n", tname, ttype, ttarget, tstate, tnode, trestart_count, tlast_restart)
else
printf( "%-40s %-14s %-12s %-15s %-15s %-15s %-20s\n", tname, ttype, ttarget, tstate, tnode, trestart_count, tlast_restart)
}
}'
# End of variable: format_crs_stat


printf "\n\n%-40s %-14s %-12s %-15s %-15s %-15s %-20s %s\n" "Resource Name" "Resource Type" "Target" "State" "Node" "Restart count" "Last Restart" "State Details"
printf "%-40s %-14s %-12s %-15s %-15s %-15s %-15s %s\n" "----------------------------------------" "--------------" "------------" "------------" "---------------" "--------------" "--------------------" "---------------"

if [[ ${GRID_VER} == "11.2" ]] ; then
format_output=${format_crs_status_resource}
if [[ -z $1 ]] ; then
${GRID_HOME}/bin/crsctl status resource -v | awk "${format_output}"
else
${GRID_HOME}/bin/crsctl status resource -v | awk "${format_output}" | grep -i "$1"
fi
else
if [[ -e ${GRID_HOME}/bin/crs_stat ]] ; then
format_output=${format_crs_stat}
if [[ -z $1 ]] ; then
${GRID_HOME}/bin/crs_stat | awk -F= "${format_output}"
else
${GRID_HOME}/bin/crs_stat | awk -F= "${format_output}" | grep -i "$1"
fi
else
echo "crs_stat was not found in the ${GRID_HOME}/bin"
fi
fi

printf "\n"
exit 0
 
Old 03-14-2012, 12:16 PM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

Deleted - mis-read data file ... cheers, makyo

Last edited by makyo; 03-14-2012 at 12:22 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 06:09 AM
SED multiple lines masterdam79 Linux - Newbie 6 10-29-2009 04:25 AM
Multiple lines in terminal seabass341 Linux - Newbie 6 06-08-2009 10:29 PM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
ISDN multiple lines schimmelpilz Linux - Newbie 1 02-24-2004 05:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration