The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
capturing output from top and format output new2ss Shell Programming and Scripting 4 02-24-2009 09:26 PM
Output format - comparison with I/p file velappangs Shell Programming and Scripting 1 04-03-2008 06:31 AM
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 03:03 PM
File Format issue: Output of sqlplus deepakgang UNIX for Dummies Questions & Answers 2 10-25-2007 03:56 AM
Format the output of file getdpg Shell Programming and Scripting 9 01-24-2006 12:50 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
becksram123 becksram123 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 6
format the output from a file

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

thanxs in advance
  #2 (permalink)  
Old 07-02-2009
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
try out this..

Code:
NoOfWords=0
while read LINE
do
        NoOfWords=`echo $LINE|wc -w|awk '{print $1}'`
        #echo "NoOfWords : [$LINE][$NoOfWords]"
        if [ "$NoOfWords" -eq "1" ]
        then
                echo "$OutString " " $LINE"
        elif [ "$NoOfWords" -eq "10" ]
        then
                OutString=`echo $LINE|awk '{printf "%s %s", $10,$4}'`
        elif [ "$NoOfWords" -eq "11" ]
        then
                OutString=`echo $LINE|awk '{printf "%s %s %s", $11,$4,$5}'`
        fi
done < Filename

Note : instead of Filename, you have to give the input filename.
  #3 (permalink)  
Old 07-03-2009
kshji's Avatar
kshji kshji is offline
Registered User
  
 

Join Date: Jun 2009
Location: Finland
Posts: 236
Done using without external programs like awk.
1st version is generic, remove extra data from lines.
Code:
#!/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
Code:
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
  #4 (permalink)  
Old 07-03-2009
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Or...
Code:
awk -F '(Following are the |[dD]omains running in the server )' 'NF>1{x=$3 OFS $2}NF==1{print x $1}' file1
...gives...
Code:
Ram-pc Process_Scheduler VPORCL
Ram-pc Application Server VPORCL01
Ram-pc Application Server VPORCL02
  #5 (permalink)  
Old 07-03-2009
thanhdat's Avatar
thanhdat thanhdat is offline
Registered User
  
 

Join Date: Aug 2008
Location: Paris
Posts: 107
my solution is longer than ygor's but u can try ^_^

Code:
awk '{ if(NF==1) printf ("%s %s\n", text, $NF);else if (NF==10) text = $10 OFS $4; else if(NF==11)  text = $11 OFS $4 OFS $5; }' test.txt
  #6 (permalink)  
Old 07-05-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
Code:
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
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0