Adding and then separating the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding and then separating the output
# 1  
Old 10-19-2011
Adding and then separating the output

Hi

I have this output

Code:
/vol/vol0 4GB
/vol/nonprod00 682GB
/vol/prod00 3GB
/vol/nasp_archive 201GB
/vol/nasp_iface 92GB
/vol/nasp_bsi 0GB
/vol/nasp_vertex 0GB
/vol/nasp_sapmnt_mp2 1GB
/vol/nasp_sapmnt_prd 52GB
/vol/nasp_sapmnt_srp 1GB
/vol/nasp_smd 1GB
/vol/nasp_ccms 0GB
/vol/nasp_saptrans_erp 45GB
/vol/nasp_saptrans_mip 4GB
/vol/nasp_saptrans_ndp 25GB
/vol/nasp_saptrans_srm 7GB
/vol/nasp_sapmnt_ndp 2GB
/vol/sharedump 0GB
/vol/arcsight 506GB
/vol/sap_depot 355GB
/vol/trp_sapmnt_sq1 2GB
/vol/trp_sapmnt_sq2 2GB
/vol/cnfo_prd 0GB
/vol/ztrap 0GB
/vol/hpux_cnprd 47GB
/vol/cn_prd 29GB
/vol/fixes 0GB
/vol/prod04 3061GB

I need to add the second column and insert a space at every 1TB.
Help please! Thanks
# 2  
Old 10-19-2011
Code:
$
$
$ cat f34
/vol/vol0 4GB
/vol/nonprod00 682GB
/vol/prod00 3GB
/vol/nasp_archive 201GB
/vol/nasp_iface 92GB
/vol/nasp_bsi 0GB
/vol/nasp_vertex 0GB
/vol/nasp_sapmnt_mp2 1GB
/vol/nasp_sapmnt_prd 52GB
/vol/nasp_sapmnt_srp 1GB
/vol/nasp_smd 1GB
/vol/nasp_ccms 0GB
/vol/nasp_saptrans_erp 45GB
/vol/nasp_saptrans_mip 4GB
/vol/nasp_saptrans_ndp 25GB
/vol/nasp_saptrans_srm 7GB
/vol/nasp_sapmnt_ndp 2GB
/vol/sharedump 0GB
/vol/arcsight 506GB
/vol/sap_depot 355GB
/vol/trp_sapmnt_sq1 2GB
/vol/trp_sapmnt_sq2 2GB
/vol/cnfo_prd 0GB
/vol/ztrap 0GB
/vol/hpux_cnprd 47GB
/vol/cn_prd 29GB
/vol/fixes 0GB
/vol/prod04 3061GB
$
$
$ perl -ane 'chomp; $F[1]=~s/GB//; $s+=$F[1]; $m=int($s/1000); $nl=$m>$p ? "\n":""; printf("%-40s  %7s GB%s\n",$_,$s,$nl); $p=$m' f34
/vol/vol0 4GB                                   4 GB
/vol/nonprod00 682GB                          686 GB
/vol/prod00 3GB                               689 GB
/vol/nasp_archive 201GB                       890 GB
/vol/nasp_iface 92GB                          982 GB
/vol/nasp_bsi 0GB                             982 GB
/vol/nasp_vertex 0GB                          982 GB
/vol/nasp_sapmnt_mp2 1GB                      983 GB
/vol/nasp_sapmnt_prd 52GB                    1035 GB
 
/vol/nasp_sapmnt_srp 1GB                     1036 GB
/vol/nasp_smd 1GB                            1037 GB
/vol/nasp_ccms 0GB                           1037 GB
/vol/nasp_saptrans_erp 45GB                  1082 GB
/vol/nasp_saptrans_mip 4GB                   1086 GB
/vol/nasp_saptrans_ndp 25GB                  1111 GB
/vol/nasp_saptrans_srm 7GB                   1118 GB
/vol/nasp_sapmnt_ndp 2GB                     1120 GB
/vol/sharedump 0GB                           1120 GB
/vol/arcsight 506GB                          1626 GB
/vol/sap_depot 355GB                         1981 GB
/vol/trp_sapmnt_sq1 2GB                      1983 GB
/vol/trp_sapmnt_sq2 2GB                      1985 GB
/vol/cnfo_prd 0GB                            1985 GB
/vol/ztrap 0GB                               1985 GB
/vol/hpux_cnprd 47GB                         2032 GB
 
/vol/cn_prd 29GB                             2061 GB
/vol/fixes 0GB                               2061 GB
/vol/prod04 3061GB                           5122 GB
 
$
$
$

tyler_durden
# 3  
Old 10-19-2011
Code:
awk '{print; sum+=$2;if (sum-t>1000){t=int(sum/1000)*1000; printf RS}}' infile

# 4  
Old 10-19-2011
try

Code:
cat <filename>|tr ' ' '     '
(or)
tr -s ' ' '     ' < filename

# 5  
Old 10-20-2011
Hi

Thanks for the responses, however the output is good except for the last one

Code:
/vol/prod04 3061GB

That one should be alone since it is over 1TB

As for madanlee not sure what your code is.
# 6  
Old 10-20-2011
Quote:
Originally Posted by bombcan
...the output is good except for the last one
Code:
/vol/prod04 3061GB

That one should be alone since it is over 1TB
...
Code:
$
$ cat f34
/vol/vol0 4GB
/vol/nonprod00 682GB
/vol/prod00 3GB
/vol/nasp_archive 201GB
/vol/nasp_iface 92GB
/vol/nasp_bsi 0GB
/vol/nasp_vertex 0GB
/vol/nasp_sapmnt_mp2 1GB
/vol/nasp_sapmnt_prd 52GB
/vol/nasp_sapmnt_srp 1GB
/vol/nasp_smd 1GB
/vol/nasp_ccms 0GB
/vol/nasp_saptrans_erp 45GB
/vol/nasp_saptrans_mip 4GB
/vol/nasp_saptrans_ndp 25GB
/vol/nasp_saptrans_srm 7GB
/vol/nasp_sapmnt_ndp 2GB
/vol/sharedump 0GB
/vol/arcsight 506GB
/vol/sap_depot 355GB
/vol/trp_sapmnt_sq1 2GB
/vol/trp_sapmnt_sq2 2GB
/vol/cnfo_prd 0GB
/vol/ztrap 0GB
/vol/hpux_cnprd 47GB
/vol/cn_prd 29GB
/vol/fixes 0GB
/vol/prod04 3061GB
$
$ perl -ane 'chomp; $F[1]=~s/GB//; $s+=$F[1]; $m=int($s/1000);
             $enl=$m>$p ? "\n":""; $bnl=$m>($p+1) ? "\n":"";
             printf("%s%-40s  %7s GB%s\n",$bnl,$_,$s,$enl); $p=$m
            ' f34
/vol/vol0 4GB                                   4 GB
/vol/nonprod00 682GB                          686 GB
/vol/prod00 3GB                               689 GB
/vol/nasp_archive 201GB                       890 GB
/vol/nasp_iface 92GB                          982 GB
/vol/nasp_bsi 0GB                             982 GB
/vol/nasp_vertex 0GB                          982 GB
/vol/nasp_sapmnt_mp2 1GB                      983 GB
/vol/nasp_sapmnt_prd 52GB                    1035 GB
 
/vol/nasp_sapmnt_srp 1GB                     1036 GB
/vol/nasp_smd 1GB                            1037 GB
/vol/nasp_ccms 0GB                           1037 GB
/vol/nasp_saptrans_erp 45GB                  1082 GB
/vol/nasp_saptrans_mip 4GB                   1086 GB
/vol/nasp_saptrans_ndp 25GB                  1111 GB
/vol/nasp_saptrans_srm 7GB                   1118 GB
/vol/nasp_sapmnt_ndp 2GB                     1120 GB
/vol/sharedump 0GB                           1120 GB
/vol/arcsight 506GB                          1626 GB
/vol/sap_depot 355GB                         1981 GB
/vol/trp_sapmnt_sq1 2GB                      1983 GB
/vol/trp_sapmnt_sq2 2GB                      1985 GB
/vol/cnfo_prd 0GB                            1985 GB
/vol/ztrap 0GB                               1985 GB
/vol/hpux_cnprd 47GB                         2032 GB
 
/vol/cn_prd 29GB                             2061 GB
/vol/fixes 0GB                               2061 GB
 
/vol/prod04 3061GB                           5122 GB
 
$
$

tyler_durden
# 7  
Old 10-20-2011
Hi durden_tyler

Why do you have the other amounts of GB on the far right. I don't have that in my file and don't need them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Separating output after final character

I'm trying to write a script that will email the contents of my Application folder to me. cd /Applications ListApps=$(ls) echo $ListApps | mail -s "Application Check" myself@myemail.com This sends it in a paragraphed block i.e: Adobe Acrobat Reader.app App Store.app Atom.app... (4 Replies)
Discussion started by: $shell_Learner
4 Replies

2. Shell Programming and Scripting

Adding hostname on the output

// AIX 6.1 pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE"} /DEVICE/ {disk=$5 printf "%s\t", $7 printf "%s\t", disk getline; printf "%s\t", substr($2, length($2)-3) ("bootinfo -s "... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. Shell Programming and Scripting

adding file extensions to split output files

Hello, I've searched this forum and others for a solution to my problem but nothing seems just right, I'm hoping I can get some help (seems like this should be easy, and I apologize if I've missed something on the forum): I have several large .fastq DNA sequence files (~20million reads,... (2 Replies)
Discussion started by: ljk
2 Replies

4. Shell Programming and Scripting

adding data in input file if 2nd script output SUCCESS

Hi All, how can i edit my original data and add more data if my 2nd script outputs SUCESS? ex. input file: 1.txt nik,is,the 1script.sh if 2ndscript.sh output SUCCESS then i'm going to edit my input file and add data best,pogi.. sample outputdata. nik,is,the,best,pogi 2ndscript.sh... (3 Replies)
Discussion started by: nikki1200
3 Replies

5. Shell Programming and Scripting

separating folders

I have folder like main. inside main folder there are subfolders & files like main1 main2 main3, file1, file2, file3. I want folders main1 & main2, file1, file2 from main folder. copy them into new folder. Please suggest me how to do it. I am new to shell programming (2 Replies)
Discussion started by: ypremcha
2 Replies

6. Shell Programming and Scripting

Adding Text To |bc Output

Hello. I have this.. $ echo '2+2' | bc 4 But I want to output it as 4 MB So, can I achieve that through one single command line? Thank you. (7 Replies)
Discussion started by: aimy
7 Replies

7. Shell Programming and Scripting

adding another field to SED output

Dear experts, I have a file called "check" with contents like below i used the sed command like below to get the value of "success" and "failed" only My question is how can i get the value to include the time "03:15", so that i can get a value such as below : - Appreciate... (4 Replies)
Discussion started by: aismann
4 Replies

8. Shell Programming and Scripting

adding order number in the output file

Hello, I have a list of all order number like below: maryu01001 johnm00003 peter02234 catmy66751 For the above, all number must in 5 digits and I need to add one into the number and output a new list like below: maryu01002 johnm00004 peter02235 catmy66752 How can write a... (20 Replies)
Discussion started by: happyv
20 Replies

9. Shell Programming and Scripting

separating fields

Hi, i have a file as follows: jonathan:bonus1,bonus2 gerald:bonus1 patrick:bonus1,bonus2 My desired output is jonathan:bonus1 jonathan:bonus2 gerald:bonus1 patrick:bonus1 patrick:bonus2 my current code is cat $F | awk -F"" how should i continue the code? Can i do something... (5 Replies)
Discussion started by: new2ss
5 Replies

10. Programming

separating commands

hey there well i have a small problem with my code. when for example : " /bin/sleep 10 & ls -l mila > xyz " is entered, the program is supposed to separate the two commands 1) /bin/sleep 10 & and 2) ls -l mila > xyz. im not sure of how to achieve this. my current program stores both commands... (2 Replies)
Discussion started by: mile1982
2 Replies
Login or Register to Ask a Question