Columns and rows

echo "Month"
echo "Feb_2014"
echo "March_2014"
echo "Apr_2014"


echo "No of files"
grep ,y, Feb_2014.csv |wc -l
grep ,y, Mar_2014.csv |wc -l
grep ,y, Apr_2014.csv |wc -l


echo "Total no of success"
awk -F"," '{x+=$4}END{print x}' Feb_2014.csv
awk -F"," '{x+=$4}END{print x}' Mar_2014.csv
awk -F"," '{x+=$4}END{print x}' Apr_2014.csv

echo "Total no of failure"
awk -F"," '{x+=$5}END{print x}' Feb_2014.csv
awk -F"," '{x+=$5}END{print x}' Mar_2014.csv
awk -F"," '{x+=$5}END{print x}' Apr_2014.csv

Actual output:

Month
Feb_2014
March_2014
Apr_2014

No of files
10
12
12

Total no of success
8
8
8

Total no of failure
6
8
8

But i need the output in columns separated.As this is my 1st week of shell training Please help

Needed output:

Month           No of files            Total no of sucess        Total no of failure
Feb_2014            6                           5                          7
Mar_2014            8                           6                          6
Apr_2014            4                           4                          7

I suppose this is what you are looking for

awk -F, 'BEGIN{
       printf("%-20s%-20s%-20s%-20s\n", "Month", "No of files", "Total no of sucess", "Total no of failure")
     }
     file != FILENAME{
       if(x || y || z){
         printf("%-20d%-20d%-20d\n", z, x, y)
         x=z=y=0
       }
       file=FILENAME
       printf("%-20s",substr(file, 0, index(file, ".")-1))
     }
     /,y,/{z++}
     {x+=$4; y+=$5}
     END{
         printf("%-20d%-20d%-20d\n", z, x, y)
     }
' *.csv

Everything you need to know about awk, well almost!!

1 Like

Dude..awesome...tx for your quick reply..hope will learn shell soon :slight_smile:

Hello,
Need in printing of Menus and submenus according to the users input choice.Can u pls help?

Bio_utils Menu
1.Status
2.Configure
3.Print report
4.Rerun for particular date range

    1.Status
        1.a\) Logs collected
        1.b\) Last run information
        1.c\) Current Log
        1.d\) Current Log collection Interval
    2.Configure
        2.a\) Archival/Production Schema Name
        2.b\)Log collection Interval
        2.c\)Current Lag
    
    3.Print Report    
        3.a\)Validation report
        3.b\)UID billing report
        3.c\)BSP billing report