Need help for creating the report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help for creating the report
# 1  
Old 05-08-2013
HP Need help for creating the report

Hi,

I have a file that contains below information:

provider APESD
APESD Annual Turn $67000
Provider
XXXX Annual Turn $92000
Provider FERHG
FERHG Annual Turn $56700
Provider
ABXX Annual Turn $99000

These are just sample rows out of some 5000. I want to create a tabular report as below:

Provider Turnover
--------------------
APESD $67000
FERHG $56700

... ignoring other records because provider name is missing.
Any idea? Can I do it using awk?

regards,
juzz4fun
# 2  
Old 05-08-2013
Here is an approach using awk:
Code:
awk '
        BEGIN {
                print "Provider", "Turnover"
                print "--------", "--------"
        }
        NR%2 && NF==2 {
                p = $2
                printf "%s", p OFS
        }
        !(NR%2) && p {
                print $NF
                p = ""
        }
' OFS='\t' file

# 3  
Old 05-08-2013
Code:
awk 'BEGIN {print "Provider", "Turnover"} /[Pp]rovider/ && NF==2 {getline;print $1,$NF}'
APESD $67000
FERHG $56700

Provider with p and P, typo?
# 4  
Old 05-08-2013
Thanks Jotne and Yoda.
I did understand what Jotne has written and I get required output. 'P' or 'p' is good.

If I understood correct, getline here gets the next record or what?
# 5  
Old 05-08-2013
Yes getline gets the next line and then continue running the awk.
The awk command next, skips whatever its doing and jumps to next line.

So it search for lines that do have Provider and two fields.
Then gets the next line and print filed #1 and last to get the desired value.

Last edited by Jotne; 05-08-2013 at 05:14 PM..
# 6  
Old 05-08-2013
Wow. Something new for me...
Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a log file and creating a report script

The log file is huge and lot of information, i would like to parse and make a report . below is the log file looks like: REPORT DATE: Mon Aug 10 04:16:17 CDT 2017 SYSTEN VER: v1.3.0.9 TERMINAL TYPE: prod SYSTEM: nb11cu51 UPTIME: 04:16AM up 182 days 57 mins min MODEL, TYPE, and SN:... (8 Replies)
Discussion started by: amir07
8 Replies

2. SCO

Creating a VM

Also, in my tinkering around I was able to get SCO installed on a VM, using VM Workstation version 12.5 in a Windows 7 Pro-64 computer. I chose the VM Workstation 8.x compatibility model for my VM, an IDE hard drive at 0:0 and an IDE CD Rom at 1:0 using the physical drive of the computer. Using the... (3 Replies)
Discussion started by: jgt
3 Replies

3. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

4. Shell Programming and Scripting

Creating a filelist

I need a script that will read a filename and verify that its today's file and rename it to a standard name so that my ETL job can read it on a daily basis. If there is no file for a day, I am thinking I will just read the one before to prevent my job from failing. Another option might be a... (1 Reply)
Discussion started by: mahe23
1 Replies

5. UNIX for Dummies Questions & Answers

Creating a report from csv file.

Hi Gurus, I need your help in transforming the CSV file into some what a report format. My source file looks like below Date,ProdID,TimeID,LevelID 2010-08-31,200,M,1 2010-08-31,201,Q,2 2010-08-31,202,Y,1 2010-08-31,203,M,5 Output required is ... (9 Replies)
Discussion started by: naveen.kuppili
9 Replies

6. Shell Programming and Scripting

Creating Report file with 'vlookup' kind of structure in shell

Hi, I have some files in the following structure. File_a.txt Field_1 Pass Field_2 Pass Field_3 Pass File_b.txt Field_1 Pass Field_2 Fail Field_3 Pass File_c.txt Field_1 Fail Field_2 Pass Field_3 Pass (2 Replies)
Discussion started by: vikaskm
2 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. Shell Programming and Scripting

help!!!!!! in creating csv report

Dear All, I need the help of all the genius minds to find solution to my problem. This problem has left me in a situation like I am in middle of sea with a rubber boat , so please help me out to get out of this. Problem:-- I m using the informix database with installed on linux machine and... (6 Replies)
Discussion started by: xander
6 Replies

9. Shell Programming and Scripting

creating 10 process

can anyone tell me how to Create ten processes and display useful information about them including PID, starting-time in unix using c or c++ language. i tried to create 10 different processes using fork and exec but i couldn't display those process info:PID,STIME. my sample code ......... (2 Replies)
Discussion started by: kpkant123
2 Replies

10. Programming

creating so's

hi everyone i have a doubt about ".so" files. what is the need of ".so" files. why we use ".so" files. where we can use ".so" files. how can i create ".so" files. can u tell me a good example please thank you (6 Replies)
Discussion started by: ramesh.jella
6 Replies
Login or Register to Ask a Question