Consolidated output in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Consolidated output in shell script
# 1  
Old 03-13-2014
Consolidated output in shell script

Hi Gurus,

I have a shell script which connects to mulitple DBs and run some queries and output will be written to log file.I need the consolidated output (html format will be better)from the logfile.see below for more details about my requirement.

Actual output:
Code:
DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER         LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      ------------------------- 
DB1       XYZ             BILLED              820                    2014_06_30           109


DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER        LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      ------------------------- 
DB2      XYZ             DATA             1277                    2014_06_30           109


DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER        LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      ------------------------- 
DB3      XYZ             DATA             1277                    2014_06_30           109


DB_NAME  TABLE_OWNER     TABLE_NAME          PARTITION_NUMBER        LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      ------------------------- 
DB4      XYZ              BILLED              911              2014_06_30           109

required output:
Code:
DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER         LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      ------------------------- 
DB1       XYZ             BILLED             820                    2014_06_30           109
DB2      XYZ             DATA             1277                    2014_06_30           109
DB3      XYZ             DATA             1277                    2014_06_30           109
DB4      XYZ             BILLED             911                    2014_06_30           109

Please provide your thoughts .
# 2  
Old 03-13-2014
Code:
awk ' NR > 2 && ( /^DB_NAME/ || /^--------/ || /^$/ ) { next } 1 ' file

# 3  
Old 03-13-2014
Code:
awk 'NR<3 ||/^-/{getline; print}' file

--edit-- corrected above part (thanks anbu)
or

Code:
sed -n '1,2{p;d;}; p;n;n;n;n' file


Last edited by Scrutinizer; 03-13-2014 at 03:23 AM..
# 4  
Old 03-13-2014
Quote:
Originally Posted by Scrutinizer
Code:
awk 'NR==1; NR==1||/^-/{getline; print}' file

Code:
$ awk 'NR==1; NR==1||/^-/{getline; print}' file
DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER         LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      -------------------------
DB2      XYZ             DATA             1277                    2014_06_30           109
DB3      XYZ             DATA             1277                    2014_06_30           109
DB4      XYZ              BILLED              911              2014_06_30           109

Code:
$ awk 'NR <= 2;/^-/{getline; print}' file
DB_NAME  TABLE_OWNER     TABLE_NAME         PARTITION_NUMBER         LAST_DATE     DAYS_LEFT
-------- --------------- --------------- ----------------      -------------------------
DB1       XYZ             BILLED              820                    2014_06_30           109
DB2      XYZ             DATA             1277                    2014_06_30           109
DB3      XYZ             DATA             1277                    2014_06_30           109
DB4      XYZ              BILLED              911              2014_06_30           109

These 2 Users Gave Thanks to anbu23 For This Post:
# 5  
Old 03-13-2014
Hi guy,

Code:
sed '/^[[:blank:]]*$/d;/^[-[:blank:]]*$/,${N;/.*\n[-[:blank:]]*-[-[:blank:]]*$/d;P;D}'

# 6  
Old 03-13-2014
Hi Anbu/Scrutinizer
Thanks for the commands.
But your command returns data without headers

awk 'NR<3 ||/^-/{getline; print}' part.log

Code:
DB1       XYZ             BILLED             820                    2014_06_30           109
DB2      XYZ             DATA             1277                    2014_06_30           109
DB3      XYZ             DATA             1277                    2014_06_30           109
DB4      XYZ             BILLED             911                    2014_06_30           109

# 7  
Old 03-13-2014
Code:
awk 'NR<3 ; /^-/{getline; print}' part.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

UNIX script for consolidated email

Hi, I am working on the below script to get a disk usage report in email from multiple unix systems but the problem I am getting first email with 1 system and second email with 2 systems and finally third email with all 3 systems :) Can someone please let me know how I can get single email... (4 Replies)
Discussion started by: new2prog
4 Replies

4. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

5. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

6. Shell Programming and Scripting

Shell Script output

Hi All, Below is the shell script for which desired output is required: Shell script: #!/bin/bash . /oracle/TEST/db/tech_st/11.1.0/TEST_<hostname>.env sqlplus /nolog << EOF connect / as sysdba spool /home/oracle/db_output.log @lockwait.sql prompt Database Locks ... (1 Reply)
Discussion started by: a1_win
1 Replies

7. Shell Programming and Scripting

shell script no output

xxxxxx (4 Replies)
Discussion started by: vinayrao
4 Replies

8. Shell Programming and Scripting

[How To?] Run shell script and get output into another shell.

Hi guys, I have a simple question, I want to store the output of the following command: As you can see it is running all the time, and we get a new line every 3sec. I just want to store these new lines into a single variable, so I can use it into a script. To clear the screen, and... (4 Replies)
Discussion started by: Thireus
4 Replies

9. Shell Programming and Scripting

need to get consolidated result from logs

already have a file with below details request 1 | 2 request 2 | 3 request 1 | 4 request 2 | 5 result required in third file request 1 | 6 request 2 | 8 (3 Replies)
Discussion started by: sankasu
3 Replies

10. Shell Programming and Scripting

Shell Script Output

I'm trying to automate numerous grep searches via shell scripting. However, the output of echo is ONE line whereas grepping from the command line would give line breaks as seen in the file. For example: test.txt: 12345 - hi 12345 - how 54321 - are 12345 - you grep output would be:... (4 Replies)
Discussion started by: sharpi03
4 Replies
Login or Register to Ask a Question