AWK to extract information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK to extract information
# 1  
Old 08-15-2007
AWK to extract information

Hi all,
I am working on a shell script to extract information from a file that has output from Oracle sqlplus. The problem is that the output of a single line is spread across multiple lines and i do not know as how to extract the particular filed at ones,which spans multiple lines. Following is what the file looks like from which i am trying to extract information.

DB1 Jack_ Harris_
Anderson Godwin

DB2 Rich Rick
DB3 Rice Paul

DB4 Paul_ Darren_
Keith Gough


As you can see from the file above, the output is skewed. In the first line the second column has name Jack_Anderson, which is divided in to two lines and there is a blank line between row1 and row 2. My question is how can i extract the individual fields. For eg: the AWK $2 on first line should give me Jack_Anderson (but it only gives Jack_) and $NR==2 is a blank line, how can i eliminate this blank line in the search? I am using AWK to extract the required fields, can anyone shed light on this. I am writing this in KORN shell.

Thanks,
Harris
# 2  
Old 08-15-2007
harris.txt:
Code:
DB1 Jack_ Harris_
Anderson Godwin

DB2 Rich Rick
DB3 Rice Paul

DB4 Paul_ Darren_
Keith Gough

harris.awk:
Code:
BEGIN {
   RS=""
}
{
  for(i=1; i<=NF; i++)
    printf("[Record/Field->%d/%d]:: [%s]\n", FNR, i, $i)
}

nawk -f harris.awk harris.txt
produces:
Code:
[Record/Field->1/1]:: [DB1]
[Record/Field->1/2]:: [Jack_]
[Record/Field->1/3]:: [Harris_]
[Record/Field->1/4]:: [Anderson]
[Record/Field->1/5]:: [Godwin]
[Record/Field->2/1]:: [DB2]
[Record/Field->2/2]:: [Rich]
[Record/Field->2/3]:: [Rick]
[Record/Field->2/4]:: [DB3]
[Record/Field->2/5]:: [Rice]
[Record/Field->2/6]:: [Paul]
[Record/Field->3/1]:: [DB4]
[Record/Field->3/2]:: [Paul_]
[Record/Field->3/3]:: [Darren_]
[Record/Field->3/4]:: [Keith]
[Record/Field->3/5]:: [Gough]

# 3  
Old 08-15-2007
Thank you very much

Last edited by harris2107; 08-15-2007 at 11:41 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to extract transcript information from gff3 file

I need help to extract transcript information from gff3 file. Here is the input Chr01 JGI gene 82773 86941 . - . ID=Potri.001G000900;Name=Potri.001G000900 Chr01 JGI mRNA 82793 86530 . - . ID=PAC:27047814;Name=Potri.001G000900.1;pacid=27047814;longest=1;Parent=Potri.001G000900... (6 Replies)
Discussion started by: Maduranga
6 Replies

2. Shell Programming and Scripting

sed / awk / grep to extract information from log

Hi all, I have a query that runs that outputs data in the following format - 01/09/12 11:43:40,ADMIN,4,77,Application Group Load: Name(TESTED) LoadId(5137-1-0-1XX-15343-15343) File(/dir/dir/File.T03.CI2.RYR.2012009.11433350806.ARD) InputSize(5344) OutputSize(1359) Rows(2) Time(1.9960)... (8 Replies)
Discussion started by: jeffs42885
8 Replies

3. Shell Programming and Scripting

Extract information from file

In a particular directory, there can be 1000 files like below. filename is job901.ksh #!/bin/ksh cront -x << EOJ submit file=$PRODPATH/scripts/genReport.sh maxdelay=30 &node=xnode01 tname=job901 &pfile1=/prod/mldata/data/test1.dat ... (17 Replies)
Discussion started by: vedanta
17 Replies

4. Shell Programming and Scripting

Extract information from file

Gents, If is possible please help. I have a big file (example attached) which contends exactly same value in column, but from column 2 to 6 these values are diff. I will like to compile for all records all columns like the example attached in .csv format (output.rar ).. The last column in the... (11 Replies)
Discussion started by: jiam912
11 Replies

5. Shell Programming and Scripting

Extract information from txt file

Hello! I need help :) I have a file like this: AA BC FG RF TT GH DD FF HH (a few number of rows and three columns) and I want to put the letters of each column in a variable step by step in order to give them as input in another script. So I would like to obtain: for the 1° loop:... (11 Replies)
Discussion started by: edekP
11 Replies

6. Shell Programming and Scripting

How to extract specific information?

hi, i have a file A like this: ******************* No 2823 ******************** contig15205- G383C4U02H4G80+ is in contig15205- G383C4U02HGLXM- is in contig15205- G383C4U01C3HIZ+ is in contig15205- ... (3 Replies)
Discussion started by: the_simpsons
3 Replies

7. Shell Programming and Scripting

How to extract information from a file?

Hi, i have a file like this: <Iteration> <Iteration_iter-num>3</Iteration_iter-num> <Iteration_query-ID>lcl|3_0</Iteration_query-ID> <Iteration_query-def>G383C4U01EQA0A length=197</Iteration_query-def> <Iteration_query-len>197</Iteration_query-len> ... (9 Replies)
Discussion started by: the_simpsons
9 Replies

8. Shell Programming and Scripting

Extract information into large variable

Hello people :) That's here my first message to your forum, so I guess it would be fine ^^ I have a request about a code I want to use. Actually, my system use a large variable, including much informations but those informations can change by more and I want to extract one of thoses... (26 Replies)
Discussion started by: WolwX
26 Replies

9. UNIX for Dummies Questions & Answers

Write a script to extract information from a db

Hi I need to put together a script that will search certain tables in a db and send that data to a csv file. Basically I am importing data to a db and I want to write a script to check that all information was imported correctly. Thank you (1 Reply)
Discussion started by: ladyAnne
1 Replies

10. Shell Programming and Scripting

How do you extract the information from a library?

hi all, i am quite new with Perl (just 1 week of experience) and i am suppose to understand the usage of library, which i can't, anyway... i came across this library...i think from the linux redhat redhat.linux.lib.pl, there are a couple of functions there that can be used to retrieve information... (3 Replies)
Discussion started by: mercz
3 Replies
Login or Register to Ask a Question