Bash: create a report with grep output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: create a report with grep output?
# 1  
Old 12-30-2010
Bash: create a report with grep output?

Greetings.

I need to generate a simple report via Bash (Korn?) with this raw data

Code:
    Test_Version=V2.5.2
    Test_Version=V2.6.3
    Test_Version=V2.4.7
    Test_Version=V2.5.2
    Test_Version=V2.5.2
    Test_Version=V2.5.1
    Test_Version=V2.5.0
    Test_Version=V2.3.9
    Test_Version=V2.3.1

Ideally, I'd like to get something like this sorted output

Code:
Version    Count
    ...
    V2.5.0     1
    V2.5.1     1
    V2.5.2     3
    V2.6.3     1
    ...

I can sort the output like this (raw data is contained in ASCII files):

Code:
    find . -name "*.VER" -exec grep "Test_Version" '{}' ';' -print | grep -e "Test_Version" | sort -u

But I can't figure out how to count my records in a tabular layout. Any idea how could I do that?

Thanks!!
# 2  
Old 12-30-2010
Try: sort | uniq -c instead of sort -u
# 3  
Old 12-30-2010
Thanks for your reply. This is what I got

1)
Code:
find . -name "*.VER" -exec grep "Test_Version" '{}' ';' -print | grep -e "Test_Version" > outfile

The output of 1) looks like this

Code:
...
Test_Version=2.5.2
Test_Version=2.6.0
Test_Version=2.6.2
...

2)
Code:
cat outfile | sed 's/.*=//' | sort | uniq -c

My output looks like this:
Code:
     39 V2.0.0
   3220 V2.4.7
   7967 V2.5.0
  28463 V2.5.2

Thanks to a friend who's way more clever than me.Smilie

Al.
# 4  
Old 12-30-2010
by awk without temp file generated.

Code:
awk -F= '/Test_Version/ {a[$2]++}END{for (i in a) print a[i],i|"sort -n"}' *.VER

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to create a report using paste or with awk

Input file will be Name: serve1 has disk :Yes dev (8): Name: serve2 has disk :No dev (8): Name: serve3 has disk :No Name: serve4 has disk :Yes dev (8): Need output like that. I was using pate -d, - - - . But that need all the line in same format in this some server it has... (4 Replies)
Discussion started by: ranjancom2000
4 Replies

2. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Need to develop a bash script to create customized report from the server log

Hi, I need to develop a bash script to create customized report from the server log (red hat 5.8 64 bit Operating system). The following is one of the log for our internal application task. <2015.03.03 20:09:52 274 +0800><I><DSCTH01><http-0.0.0.0-443-2><security> GUI request succeeded for... (1 Reply)
Discussion started by: pugazhendhi_r
1 Replies

4. Shell Programming and Scripting

Create a two column output in bash

Hi! I m newbie for scripting. My requirement is to create a host file as below from the output of aws api. Hostname PrivateIP abc x.y.x.z cde a.b.c.c and so on. I have the following script, #!/bin/bash export AWS_ACCESS_KEY=abc export... (5 Replies)
Discussion started by: cuteboyucsc
5 Replies

5. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

6. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

7. Programming

How to create this on bash?

I'm trying to create a script with the ff array array 1 - foo@fee.com,fee@fee.com,fyii@fee.com (1 line) array 2 - paul what I want is to have the ff output in a text file foo@fee.com: paul fee@fee.com: paul fyii@fee.com: paul Could this be done on a bash script? I'm trying this... (1 Reply)
Discussion started by: packets
1 Replies

8. Shell Programming and Scripting

using todays date to create a report using grep

What i'm trying to do is to use grep to search through a few files for a selected daemon and only report on today's date. I think I got it sorted apart from in the txt file the date has 2 gaps between the month and the day, and the way I have the date format only puts in one gap any help to get... (3 Replies)
Discussion started by: MBN
3 Replies

9. Shell Programming and Scripting

create a report using shell

hi suppose I want to create a report where it will shows the machine name, the date & time when the report is produced. can anyone please help me to write such shell script? requesting all. Thanks (10 Replies)
Discussion started by: moco
10 Replies

10. Shell Programming and Scripting

help with awk to create report

Hi, I am trying to create a report using the following syntax: #!/bin/awk -f #script name: users_report BEGIN { FS=":" ; OFS="\t" ; print "User\tGID\tUser Name\tHome Dir\t" { print $1 , $3 , $5 , $6 } END { print "\n End of Report \n" } $> user_report /etc/passwd the output of... (5 Replies)
Discussion started by: ghazi
5 Replies
Login or Register to Ask a Question