Help with manipulating the output on a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with manipulating the output on a script
# 8  
Old 05-02-2012
What exactly is it doing, then?

...how about you post your actual input so I can write a script that deals with that?
# 9  
Old 05-02-2012
Hi,

This is the acutual output of the command.
Code:
Attribute                        Value
------------------------- ----------------------------
State                            Full Access
Active sessions                  0
Total capacity                   7.8 TB
Capacity used                    3.2 TB
Server utilization               40.8%
Bytes protected                  0 bytes
Bytes protected quota            Not configured
License expiration               Never
Time since Server initialization 203 days 21h:42m
Last checkpoint                  2012-05-02 12:45:10 PDT
Last validated checkpoint        2012-05-02 11:04:48 PDT

I need output like

Code:
Total Capacity  Utilization  Used Capacity

7.8 TB               40.2 %      3.2 TB


But right now it is printing only like these

Code:
Total Capacity ,Utilization ,Used Capacity,,,

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 05-02-2012 at 06:07 PM..
# 10  
Old 05-02-2012
Yes, that's completely different than the output you originally posted. I'll adjust my script for it.
# 11  
Old 05-02-2012
The output you want, by the way, can't be used for import into excel... how would it tell the difference between cell-separating spaces and word-separating spaces? So I've given you what you originally asked for, CSV, as in "Comma-separated value". Excel can import that easy.

Code:
# Field separator is two or more spaces
BEGIN { FS="   *";      OFS=",";        ORS="\r\n"      }
# Ignore first two lines, then store in array
NR>2 { sub(/ *$/, ""); A[$1]=$2; }

END {
        print "Total Capacity", "Utilization", "Used Capacity";
        print A["Total capacity"], A["Server utilization"], A["Capacity used"];
}

This User Gave Thanks to Corona688 For This Post:
# 12  
Old 05-02-2012
Thanks a ton .. It works like a charm .... Can you explain me the script when you have time or give me a link where I can read more about writing awk scripts ?
# 13  
Old 05-02-2012
Quote:
Originally Posted by rrb2009
Thanks a ton .. It works like a charm .... Can you explain me the script when you have time or give me a link where I can read more about writing awk scripts ?
The basic principle is that awk is one big loop of its own. It runs each outside code-block found in the script, in order, for every line it processes. You can put expressions in front of them to control when they're run, store things in variables, and so on.

It also understands columns. $1, $2, $3 and so forth refer to columns. Usually, it figures that any whitespace splits a column, but here I've told it specially that it has to be two or more spaces ( FS=" *" ). You can also transform what columns it prints out (OFS=",") and what splits lines on the way out (ORS="\r\n").

And a lot more. Even the meaning of 'line' can be altered, if you needed to use "*" instead of \n.

It has associative arrays, so you can do things like A["string"]=32; print A["string"]; and get 32 out of it.

You can even do shell-like redirection in it, in case you wanted to write to anything but stdout. print > "filename" Once you start writing to a file, it stays opened.

Code:
# The 'begin' section is run before any files are opened by awk.
# Use it to set up these variables.
BEGIN { FS="   *";      OFS=",";        ORS="\r\n"      }

# NR is the number of records.
# The code block here will only get run when NR is greater than two.
# Ergo, it ignores the first two lines.
NR>2 {
        # Get rid of some spaces at the end of the line
        sub(/ *$/, "");
        # Store like A["Total capacity"]=7.8 TB
        A[$1]=$2; }

# This code block only gets run when awk runs out of files.
END {
        # Print our titles
        print "Total Capacity", "Utilization", "Used Capacity";
        # Print the various things we stored in the array before
        print A["Total capacity"], A["Server utilization"], A["Capacity used"];
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Data manipulating script. Please HELP!

Dear friends, I'm struggling to preparing a bunch of gromacs input files, say manually. It's really a time-consuming work without any techniques. I suppose that it could be done by a smart script automatically. But I lack some basic knowledge on scripting. Please help! My original input looks... (3 Replies)
Discussion started by: liuzhencc
3 Replies

2. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

3. Shell Programming and Scripting

Manipulating variables in shell script

Hello, I know this should be simple but cant find a solution yet.I have the following in a sh script called "var" #!/bin/bash var1=0 And on another script called "main" I use a if construct: #!/bin/bash . var if then Do this else do that fi Now in "do this" part,I have to change... (8 Replies)
Discussion started by: vijai
8 Replies

4. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

5. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Red Hat

Cron task output is 0, script output is OK

I have the following cron task set to run every 15 minutes to ascertain how many users are in the system and append the result to the log. /home/pronto/cus/whoisinc >> /home/pronto/cus/whoisin.log This is the whoisinc script date +"%d-%m-%Y,%k:%M,Pronto Users,`prowho -s | grep -v... (1 Reply)
Discussion started by: scottm
1 Replies

8. Shell Programming and Scripting

Need help is manipulating a file with some arithmetic operations using bash script

Friends, I have a file with contents like: interface Serial0/4/0/0/1/1/1/1:0 encapsulation mfr multilink group 101 Now I need to manipulate the file in such a way that to all the numbers less than 163, 63 gets added and to all numbers greater than 163, 63 gets deducted.(The numbers... (2 Replies)
Discussion started by: shrijith1
2 Replies

9. UNIX for Advanced & Expert Users

Manipulating Standout Output

I am trying to insert tab's in place of spaces when I tail -f a log and pipe it with grep and cut. Is there a way to take the stdout and format in a way that is tabbed so that all the information is stacked appropriately. I've tried using unexpand. But that did not work. I basically need to... (2 Replies)
Discussion started by: cubs0729
2 Replies

10. UNIX for Advanced & Expert Users

Manipulating output file

I have a file containing two fields, Name and Time, with about 57 lines in this file. I am struggling to create a loop that will cut out the first ten lines of this file and echo it to the screen. Can anybody help me please. (1 Reply)
Discussion started by: mariner
1 Replies
Login or Register to Ask a Question