Script to display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to display
# 1  
Old 12-02-2009
Script to display

I have script which prints following o/p

Code:
ServerName = server1 
Proc0  :Temperature      61
Proc1  :Temperature      60
CPU 99.4% idle,

Now since i have to feed this data to another java program i want the out put as follows

Code:
Name         Proc0 Temp      Proc1 Temp            CPU Idle 
Server1           61                   61                   99.4 %

How can i do that ?
# 2  
Old 12-02-2009
to print the header you can use echo followed by the cmd

Code:
 echo "Name         Proc0 Temp      Proc1 Temp            CPU Idle" ; 
awk '{ORS = "      "; if ( $1 ~ /CPU/) print $(NF-1); else print $NF} END {print "\n"}'  abc.txt ;

Code:
Output:
Name         Proc0 Temp      Proc1 Temp            CPU Idle
server1 61      60      99.4%

# 3  
Old 12-02-2009
Code:
$
$ cat -n f7
     1  ServerName = server1
     2  Proc0  :Temperature      61
     3  Proc1  :Temperature      60
     4  CPU 99.4% idle,
$
$ cat f7 |
> perl -ne 'if (/^ServerName = (.*)$/){push @x,"Name"; push @y,$1}
>           elsif (/^(Proc\d) .* (\d+)$/){push @x,$1." Temp"; push @y,$2}
>           elsif (/^CPU ([^ ]*) .*$/){push @x,"CPU Idle"; push @y,$1}
>           END {foreach $i(@x) {printf("%-20s",$i)} print "\n";
>                foreach $j(@y) {printf("%-20s",$j)} print "\n";
>               }'
Name                Proc0 Temp          Proc1 Temp          CPU Idle
server1             61                  60                  99.4%
$
$

tyler_durden
# 4  
Old 12-02-2009
Thanks to both of you. I 'm using daptal suggestion but i need one more help on same .. i when i run this script with multiple entries ever 10 seconds it gives me following o/p and i want it on per line basis.

Code:
      61      61      18400      19199      99.9%            61      61      18400      18800      99.8%      usmtnz-dinfsi19      61      61      18400      18800      99.9%      usmtnz-dinfsi19      61      61      18400      18800      99.8%      usmtnz-dinfsi19      61      61      18400      18800      99.8%            61      61      18400      18800      99.9%            61      61      18400      18400      99.8%            61      61      18400      18400      99.9%            61      61      18400      19199      99.4%

# 5  
Old 12-02-2009
Try if this helps
Code:
awk '{ORS = "      "; if ( $1 ~ /CPU/) print $(NF-1)"\n"; else print $NF} ' abc.txt

# 6  
Old 12-03-2009
Hi daptal,

Thanks for your reply .. yesterday i tried following instead the one u gave and it started showing the o/p like i wanted ..


Code:
BEGIN {
        FS=""
        RS=""
        
}
{
        print $2 "\t" $3 "\t" $4/1000 "\t" $5/1000 "\t" 100-$6
}' test.txt


But i have another problem risen after this .. actually my text file has data like following
Code:
usmtnz-dinfsi19
72
71
20400
20800
6.0
usmtnz-dinfsi19
72
71
20400
20800
6.0
usmtnz-dinfsi19
72
71
20400
20800
5.9
usmtnz-dinfsi19


and i run the awk it just shows the first line from the file & test.txt and nothing else is shown.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with script to display space usage

Hi all, I am looking for help with a script for displaying the space available from a df - h command for / (root). The problem is: If it is below 700 MB I have jobs that are failing... Is there a way I can do a calculation? If it above 700 MB it is good, if it is below 700 MB it will fail.... (5 Replies)
Discussion started by: gartie
5 Replies

2. Shell Programming and Scripting

Script with ^M causes display issue with cat or more

I have a script to do a couple simple but repetitive commands on files that are provided to us. One of the things is to get rid of the line feeds. This is the section that is causing problems, i even cut this section into its own file to make sure nothing else was affecting it. #!/usr/bin/bash... (4 Replies)
Discussion started by: oly_r
4 Replies

3. Shell Programming and Scripting

Help with Display Shell Script

hi Friends, I am writing a shell script to extract data from sar logs for my daily analysis. I have this in sar logs HP-UX dhpcdbe1 B.11.31 U ia64 05/09/12 01:22:42 device %busy avque r+w/s blks/s avwait avserv 01:27:59 disk30 8.79 13.72 26 427 36.47 ... (3 Replies)
Discussion started by: kunwar
3 Replies

4. Shell Programming and Scripting

How to display a counter in shell script?

Hi, I am writing a script which processes large number of files in a directory. I wanto display a counter which increment after processing each file. I am processing each file in a for loop. If I echo a variable with its value increasing with each file, I will get around 5000 lines as output.... (10 Replies)
Discussion started by: jaiseaugustine
10 Replies

5. UNIX Desktop Questions & Answers

Script that will display a short message

Can anyone point me to the right direction on how to write a simple script that will display a message on any terminal when implemented? Basically I need it so the script runs at a certain time, say April 30, 2010 and that the message will be displayed to me no matter which terminal I am logged... (2 Replies)
Discussion started by: jmack123
2 Replies

6. Shell Programming and Scripting

script to display time

hey folks, i am stuc in this problem. You all might help me out. I want to write a BASH script to display time every 15 seconds using %r field descriptor. And want to clear the window each time before displaying time using clear command. Please help me out (3 Replies)
Discussion started by: manojrsb
3 Replies

7. Shell Programming and Scripting

DISPLAY Script

Good Morning I am Trying to Create a Script that @ startup sets the DISPLAY Variable So i can Use Plink to Start X11 Applications (*\plink.exe **** sh display.sh; eclipse) Tools : Xming and Putty/Plink SSH-Connection to LinuxServer I startet with sh and that didnt work so after sh now... (8 Replies)
Discussion started by: FruF
8 Replies

8. Shell Programming and Scripting

Script to display time difference..

Hi i've written a script which reads last two line of the log file from N number of servers and send the mail by redirecting to a particular log file. And the two lines is displayed below. Oracle Q03 Begin Hot BACKUP Time: 07/23/08 18:35:46 Oracle Q03 End Hot BACKUP Time: 07/24/08 14:18:15... (1 Reply)
Discussion started by: suri.tyson
1 Replies

9. UNIX for Dummies Questions & Answers

Shell Script Display?

I remember learning that there is a way to make a shell script display the script itself to standard output while the script is being executed but I can't find how to do that. Any pointers? (2 Replies)
Discussion started by: wmosley2
2 Replies
Login or Register to Ask a Question