format the output from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format the output from a file
# 1  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-03-2009
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  
Old 07-03-2009
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  
Old 07-03-2009
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  
Old 07-05-2009
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

2. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

3. Shell Programming and Scripting

format a file to this output

hi i need some help over here.. please help i have a log file as per below --------------------------------------------------------------------------------------------------------- JOB START DATE : 20110510204513 JOB ID : us2cap3ds9... (6 Replies)
Discussion started by: sitaldip
6 Replies

4. Shell Programming and Scripting

Help me to command to output file format.

Dear Master. Help me to command to out put. Ex log. "<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom> <txid>17251032659</txid> <authentication> <user>admin</user> <password>Amrduoi</password> </authentication> <destination> <msisdn>1111111</msisdn> ... (2 Replies)
Discussion started by: ooilinlove
2 Replies

5. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

6. Shell Programming and Scripting

Change file output format

I have a file which has following contents usmtnz-dinfsi19 62 61 18400 18800 99.7 usmtnz-dinfsi19 62 61 18400 18800 99.7 i want the o/p to be like date (7 Replies)
Discussion started by: fugitive
7 Replies

7. Shell Programming and Scripting

format output in csv file

I am sending the output of a file to .csv file. The output should look like this: Total Customers Processed:,8 Total Customers Skipped:,0 Total Customers Added:,8 Total Customers Changed:,0 Total Policies Deleted:,0 Total Policies Failed:,0 total:,8 Now i want this output in... (1 Reply)
Discussion started by: Prashant Jain
1 Replies

8. Shell Programming and Scripting

format file output

Hi, I am trying to put a script together that allows for a command to be executed and then the output goes to a .html file. I am running the script on HPUX. I run: /var/fl/user/lmutil lmstat -a -c license_lic.dat > /web/results.html This saves the command to a .html file but the text is... (1 Reply)
Discussion started by: zerbitated
1 Replies

9. Shell Programming and Scripting

Output format - comparison with I/p file

Hi, I have a file which contains more than 1 lakh records like following: a. name, id, city, state, country, phone (Expected I/P file format) name, id, city,, state, country, phone (Current I/P file format ) I want to achieve following tasks, a, Remove the extra comma in the... (1 Reply)
Discussion started by: velappangs
1 Replies

10. Shell Programming and Scripting

Format the output of file

hello all Script and example of file #!/bin/sh #sh gdata.sh /users/testsuite/db/appl/ DATE=`date '+20%y-%m-%d'` echo $DATE for i in ${1}/$DATE/* ; do find $i -name daily -prune -o -name run.log -print -exec grep -c ! {} \; done > test.log. The test.log contains output like this ... (9 Replies)
Discussion started by: getdpg
9 Replies
Login or Register to Ask a Question