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
# 1  
Old 05-02-2012
Help with manipulating the output on a script

Hi All,

I have a question on eliminating spaces from a output.

A command returns me output like this

Code:
Attribute                            Value 
---------------                   ---------------

Total Capacity                     500 GB 
Utilization                            10 % 
Used Capacity                      50 GB

I need to convert the output like this to a csv or xls file

Code:
Total Capacity   Utilization     Used Capacity 

   500 GB            10%              50 GB

Can anyone help how can i do this using sed or awk ? I tried few but nothing worked ? Can anyone help me ?

Moderator's Comments:
Mod Comment Code tags for code, please.
# 2  
Old 05-02-2012
Code:
$ cat totalcap.awk

# Field separator is two or more spaces
# ORS="\r\n" makes the text Windows-readable,
# omit it to make an ordinary flatfile.
BEGIN { FS="   *"; ORS="\r\n"     }
# Ignore first three lines, then store in array, keep order in O
NR>3 { sub(/ *$/, ""); A[$1]=$2; O[++L]=$1 }

END {
        S="";   for(N=1; N<=L; N++) S=S","O[N];
        print substr(S, 2);
        S="";   for(N=1; N<=L; N++) S=S","A[O[N]];
        print substr(S, 2);
}

$ awk -f totalcap.awk data

Total Capacity,Utilization,Used Capacity
500 GB,10 %,50 GB

$

Depending on your system you may need to use nawk or gawk instead of awk.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-02-2012
Thanks for your quick help. How should i run this along with the command ?

command | awk -f <awkfilename> or awk -f <awkfilename> ' command ' ?
# 4  
Old 05-02-2012
Code:
command | awk -f totalcap.awk > outputfile

# 5  
Old 05-02-2012
Hi,

I am sorry , the first command i posted works but my command output has couple of other statistics also apart from the 3 I gave in the example. How to pick only those 3 ? like row 3,4 & 5 out of 10 rows.
# 6  
Old 05-02-2012
You know, I could tell the input you posted was edited and reduced, so I was very very careful to make sure my code could include things you didn't ask for Smilie

I guess I guessed in the wrong direction.

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

END {
        print "Total Capacity", "Utilization", "Used Capacity";
        print A["Total Capacity"], A["Utilization"], A["Used Capacity"];
}

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 05-02-2012
Thanks once again but it is not printing the values of these 3. sorry to keep you bugging
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