Greping columns data from file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping columns data from file.
# 1  
Old 08-05-2008
Question Greping columns data from file.

Hi i am using shell script which perform oracle database query and after that output is redirect to some temporary file.

the output of this file looks like
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Aug 5 16:08:06 2008

Copyright (c) 1982, 2005, Oracle. All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL>
HOUR COUNT(*)
---------- ----------
11 30
12 12
15 11

SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options


Now in fact i want to extract the columns data HOUR and COUNT(*) .Then how can i extract or grep this columns from this temporary file.
any help ..

//regards
sunil
# 2  
Old 08-05-2008
Something like this should work:
Image
Code:
awk '/HOUR COUNT/{f=1}f' file

Regards
# 3  
Old 08-05-2008
Use -B option with grep. like,

To print below 5 lines of search pattern,
Code:
grep -B 5 "HOUR COUNT" filename

It will display,
Quote:
---------- ----------
11 30
12 12
15 11
- nilesh
# 4  
Old 08-05-2008
in first one when i give below command

#awk '/HOUR COUNT/{f=1}f' <filename>

result::
awk: syntax error near line 1
awk: bailing out near line 1


i dnt know size of column it can be n number in size
for currentr case it is giving me below response.
grep: illegal option -- B
Usage: grep -hblcnsviw pattern file . . .
# 5  
Old 08-05-2008
Quote:
Originally Posted by esungoe
in first one when i give below command

#awk '/HOUR COUNT/{f=1}f' <filename>

result::
awk: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
# 6  
Old 08-05-2008
Couldn't you just run sqlplus with the -silent option in the first place?
# 7  
Old 08-05-2008
Great era,
Thanks i was not aware of -silent feature of sqlplus ..

now without greping i got my desire output.

//Regards
Sunil Goyal
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delimiter appending in a data file if we receive a less columns than expected

Required No.of field = 12 Let say you got a “~” delimited input file and this file has 6 input fields and now I want to add 12-5=7 number of “~” into this input file in order to make it 12 fields datafile can have n number of records ex., a~b~c~d~12~r a~b~c~d~12~r a~b~c~d~12~r... (19 Replies)
Discussion started by: LJJ
19 Replies

2. Shell Programming and Scripting

Insert space or pattern between columns in a data file

I have a data file where three data sets are written in three columns. Can I increase the space between the columns without reading them? Also can I insert particular patterns, say comma between 1st and 2nd column and colon between 2nd and 3rd column? (13 Replies)
Discussion started by: hbar
13 Replies

3. Shell Programming and Scripting

validating data in columns and writing them to new file

I have a file that contains records in the below format: 23857250998423948239482348239580923682396829682398094823049823948 23492780582305829852095820958293582093585823095892386293583203248 23482038509825098230958235234230502958205983958235820358205892095... (10 Replies)
Discussion started by: shellhelp
10 Replies

4. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

Finding standard deviation for all columns in a data file

Hi All, I want someone to modify the below script from this forum so that it can be used for all columns in the file( instead of only printing column 3 mean and standard deviation values). I don't know how to loop around all the columns. ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

6. UNIX and Linux Applications

Initializing columns to NULL an saving data to a new file

Hi I've been trying to delete columns from a file, and the best option I could come up was to initialise them to NULL. The reason for this is because I need to compare the differences between 2 files with those specific columns excluded. Here is my script: #!/bin/bash... (4 Replies)
Discussion started by: ladyAnne
4 Replies

7. UNIX for Advanced & Expert Users

Create a file and enter data in columns

Hello!!!!!!!! I have an issue regarding inserting records in a file columnwise.Is it possible using awk/nawk script? Example: File1: 1|AAA|25|2 5|qqe|20|7 4|wer|31|81 I need to create a second file in which data can be inserted in a columnwise manner i.e. File2: AAA|25|1|2... (1 Reply)
Discussion started by: abhijeet1409
1 Replies

8. Shell Programming and Scripting

Need Help for Adding Three new columns in existing file from fatching data from file

not required this time (36 Replies)
Discussion started by: Sandeep_Malik
36 Replies

9. Shell Programming and Scripting

Help with Data Positioning from Columns in a flat file.

Hi All, I have used this forum many times to solve my many scripting problems. This time, I would like to seek some answers to a problem that I've been head scratching quite a bit on. My Example: I am converting a 2000-byte file into a 300-byte file this file has no delimiters and hardly any... (3 Replies)
Discussion started by: oott1
3 Replies
Login or Register to Ask a Question