Sponsored Content
Top Forums Shell Programming and Scripting Print all the fields of record using awk Post 302526667 by raghavendra.nsn on Wednesday 1st of June 2011 06:41:45 AM
Old 06-01-2011
Print all the fields of record using awk

Hi,

i want to generate print statement using awk.
i have 20+ and 30+ fields in each line

Now its priting only first eight fields print statement as output not all.

my record is as shown below filename
HTML Code:
TFP_DNS,saidata.US_TFP_DNS_1,IMSI,APN,IMEI,EVENT_AMOUNT,CAUSE_PROC,CHARGING_INFO,RAG1,RAG2,RAG3,RAG4,RAG5,RAG6,RAG7,RAG8,RAG9,RAG10,RAG11
TFP_DNS,saidata.PS_TFP_DNS_1_HOUR,IMSI,APN,IMEI,EVENT_AMOUNT,CAUSE_PROC,CHARGING_INFO,RAG1,RAG2,RAG3,RAG4,RAG5,RAG6,RAG7,RAG8,RAG9,RAG10
TFP_DNS,saidata.PS_TFP_DNS_1_DAY,IMSI,APN,IMEI,EVENT_AMOUNT,CAUSE_PROC,CHARGING_INFO,RAG1,RAG2,RAG3,RAG4,RAG5,RAG6,RAG7,RAG8,RAG9,
TFP_DNS,saidata.PS_TFP_DNS_1_WEEK,IMSI,APN,IMEI,EVENT_AMOUNT,CAUSE_PROC,CHARGING_INFO,RAG1,RAG2,RAG3,RAG4,RAG5,RAG6,RAG7,RAG8,
TFP_DNS,saidata.PS_TFP_DNS_1_MONTH,IMSI,APN,IMEI,EVENT_AMOUNT,CAUSE_PROC,CHARGING_INFO,RAG1,RAG2,RAG3,RAG4,RAG5,RAG6,RAG7,RAG8,RAG9,RAG10,RAG11,RAG12,RAG13,RAG14  
Code:
 
my awk calling in script is 
awk -F"," -v var=$sql_dir -f do.agg.out fiiename.csv 
 
and awk file do.agg.out looks like 
 
/US_/ { 
 print "spool /opt/nsn/robot/spool/Actual_RAW_JOB.txt; " > ""var"/RAW-Data-out.sql"
  for( i = 2; i <=NF; i++ )  
  {
           print " select count(*), "$i" FROM "$1" where "$i" in (select distinct "$i" from "$1") group by "$i" order by "$i" asc; \n"  >> ""var"/RAW-Data-out.sql"
  }
          print " select count(*) from "$1";\n" >>  ""var"/RAW-Data-out.sql"
   print " spool off; \n exit; " >> ""var"/RAW-Data-out.sql" 
    }

its working fine but its displaying only 8 records (print statement) in for loop instead of number of fields ??

let me know anything wrong i am doing ?

Thanks,
Raghavendra
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: record has too many fields

Hi, I'm trying this command - but get this error. Do you guys have any workaround for this? cat tf|sed 's/{//g'|sed 's/,//g'|awk '{for (i=1;i<=NF;i++) {if ($i == "OPTIME") {k = i + 2; print $i,$k}}}' awk: record `2005 Jul 28 17:35:29...' has too many fields record number 15 This is how... (3 Replies)
Discussion started by: chaandana
3 Replies

2. Shell Programming and Scripting

awk /nawk :: print the everything except the first and the last fields

format of file1 "file1.txt" 1 2 3 4 A B C XX YY ZZ AA WWW The output must contain except the first and last column the output must be 2 3 B YY ZZ AA (8 Replies)
Discussion started by: centurion_13
8 Replies

3. Shell Programming and Scripting

awk - print record with both string1 and string2

How do I use awk to find the records in a file that contains two specific strings? I have tried piping and using awk two times, but I don't know how to do it in one action. (2 Replies)
Discussion started by: locoroco
2 Replies

4. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

5. Shell Programming and Scripting

AWK exclude first and last record, sort and print

Hi everyone, I've really searched for a solution to this and this is what I found so far: I need to sort a command output (here represented as a "cat file" command) and from the second down to the second-last line based on the second row and then print ALL the output with the specified section... (7 Replies)
Discussion started by: dentex
7 Replies

6. Shell Programming and Scripting

AWK print initial record and double

I have an initial record 0.018 I would like a script that would for i=0;i<200;i++ print 0.018*1 0.018*2 0.018*3 0.018*4 ... 0.018*200 using newline. (7 Replies)
Discussion started by: chrisjorg
7 Replies

7. UNIX for Dummies Questions & Answers

keeping last record among group of records with common fields (awk)

input: ref.1;rack.1;1 #group1 ref.1;rack.1;2 #group1 ref.1;rack.2;1 #group2 ref.2;rack.3;1 #group3 ref.2;rack.3;2 #group3 ref.2;rack.3;3 #group3 Among records from same group (i.e. with same 1st and 2nd field - separated by ";"), I would need to keep the last record... (5 Replies)
Discussion started by: beca123456
5 Replies

8. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

9. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

10. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies
DB2_NUM_FIELDS(3)							 1							 DB2_NUM_FIELDS(3)

db2_num_fields - Returns the number of fields contained in a result set

SYNOPSIS
int db2_num_fields (resource $stmt) DESCRIPTION
Returns the number of fields contained in a result set. This is most useful for handling the result sets returned by dynamically generated queries, or for result sets returned by stored procedures, where your application cannot otherwise know how to retrieve and use the results. PARAMETERS
o $stmt - A valid statement resource containing a result set. RETURN VALUES
Returns an integer value representing the number of fields in the result set associated with the specified statement resource. Returns FALSE if the statement resource is not a valid input value. EXAMPLES
Example #1 Retrieving the number of fields in a result set The following example demonstrates how to retrieve the number of fields returned in a result set. <?php $sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed"; $stmt = db2_prepare($conn, $sql); db2_execute($stmt, $sql); $columns = db2_num_fields($stmt); echo "There are {$columns} columns in the result set."; ?> The above example will output: There are 4 columns in the result set. SEE ALSO
db2_execute(3), db2_field_display_size(3), db2_field_name(3), db2_field_num(3), db2_field_precision(3), db2_field_scale(3), db2_field_type(3), db2_field_width(3). PHP Documentation Group DB2_NUM_FIELDS(3)
All times are GMT -4. The time now is 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy