hi ,
i need to format the output which is availble in a file
file output is
Following are the Process_Scheduler Domains running in the server Ram-pc
VPORCL
Following are the Application Server domains running in the server Ram-pc
VPORCL01
VPORCL02
these value VPORCL,VPORCL01... are dynamic value i need to print this out int his format
hostname domaintype domain name
Ram-pc Process_Scheduler VPORCL
Ram-pc Application Server VPORCL01
Ram-pc Application Server VPORCL02
Done using without external programs like awk.
1st version is generic, remove extra data from lines.
#!/usr/bin/ksh
while read id restline
do
case "$restline" in
"") # only id, so print line
print "$prevheader $id"
;;
*) # long line, remove constant/extra strings
str=${restline/are the/}
str=${str/running in the server/}
str=${str/[Dd]omains/}
# what we have ? Values
prevheader=$str
;;
esac
done < input.txt
And then to solution for this case. Need to change field order
print "____________________________________________________"
# change fld order
while read id restline
do
case "$restline" in
"") print "$prevheader $id" ;;
*) str=${restline/are the/}
str=${str/running in the server/}
str=${str/[Dd]omains/}
# fields to array flds
set -A flds -- $str
lastfld=${#flds[*]}
# first id = 0
((lastfld-=1))
# last field value
prevheader=${flds[$lastfld]}
((lastfld-=1))
# rest fields
fld=0
while ((fld<=lastfld))
do
prevheader="$prevheader ${flds[$fld]}"
((fld+=1))
done
;;
esac
done < input.txt
my($type,$name);
while(<DATA>){
if(/.*the\s+(.*)\s+[Dd]omains.*server\s+(.*)/){
$type=$1;
$name=$2;
next;
}
print $name," ",$type," ",$_;
}
__DATA__
Following are the Process_Scheduler Domains running in the server Ram-pc
VPORCL
Following are the Application Server domains running in the server Ram-pc
VPORCL01
VPORCL02