Sponsored Content
Full Discussion: Urgent - Looping using AWK
Top Forums Shell Programming and Scripting Urgent - Looping using AWK Post 302125375 by skyineyes on Thursday 5th of July 2007 02:58:50 AM
Old 07-05-2007
Here is my code

#!/usr/bin/sh

while read v1 v2 v3 v4 v5 v6
do
echo "$v1 $v4 $v6"| awk ' { printf("%-40s%-40s%-40s\n",$v1,$v4,$v6,
) } '

done < file.txt

But i am getting following error messages

Syntax Error The source line is 1.
The error context is
{ >>> printf("%-40s%-40s%-40s\n",$v1,$v4,$v6,) <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
Syntax Error The source line is 1.
The error context is
{ >>> printf("%-40s%-40s%-40s\n",$v1,$v4,$v6,) <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.


Kindly tell what should be done to get formatted output?
~


Quote:
Originally Posted by anbu23
Code:
while read v1 v2 v3 v4 v5
do
echo $v1 $v3 $v5
done < file

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Looping in awk

Can somebody give me a cleaner way of writing the following script. I was thinking that I could use a loop in the awk statement. It works fine the way it is but I just want the script to be cleaner. #!/usr/bin/sh for r in 0 1 2 3 4 5 6 do DAY=`gdate --date="${r} days ago" +%m\/%d\/%y`... (3 Replies)
Discussion started by: keelba
3 Replies

2. Shell Programming and Scripting

Awk: looping problem!

I am having a problem with awk when I run it with a loop. It works perfectly when I echo a single line from the commandline. For example: echo 'MFG009 9153852832' | awk '$2 ~ /^0-9]$/{print $2}' The Awk command above will print field 2 if field 2 matches 10 digits, but when I run the loop... (5 Replies)
Discussion started by: cstovall
5 Replies

3. Shell Programming and Scripting

looping and awk/sed help

I am pretty new to this, but imagine what I am trying to do is possible iI am trying to make an automated DB comparison tool that selects all columns in all tables and compares them to the same thing in another DB. anyway I have created 2 files to help with this the first file is a... (13 Replies)
Discussion started by: Zelp
13 Replies

4. UNIX for Dummies Questions & Answers

Help with AWK looping

I'm trying to parse a configuration text file using awk. The following is a sample from the file I'm searching. I can retrieve the formula and recipe names easily but now I want to take it one step farther. In addition to the formula name, I would like to also get the value of the attribute... (6 Replies)
Discussion started by: new2awk
6 Replies

5. Shell Programming and Scripting

looping in awk

How do I remove last comma? echo "xx yy zz" | awk 'BEGIN{FS=" "}{for (i=1; i<=NF; i++) printf "%s,", $i}'output: xx,yy,zz, required output: xx,yy,zz or (ideally!): xx, yy & zz many thanks in advance! (4 Replies)
Discussion started by: euval
4 Replies

6. Shell Programming and Scripting

Looping within the elements of a file using awk

Hi all, I have a file containing 5000 rows and 4 columns. I need to do a loop within the rows based on the values of column 3. my sample data is formatted like the ones below: what i need to do is to make a loop that will allow me to plot the values of x,y,values corresponding to month 1 to month... (10 Replies)
Discussion started by: ida1215
10 Replies

7. Shell Programming and Scripting

AWK looping over 2 variables

I would like to loop over variables i and j consecutively, { a = -6.7 b = 7.0 c =0.1 { for (i = 0; i<=(b-a)/c; i++) for (j = 1; j<=(b-a)/c; j++) '$1<=(a+j*c)&&$1>=(a+i*c)' FILENAME > output_j '{print $2}' output_j > output_j_f } I essentially want to print the range of $1... (9 Replies)
Discussion started by: chrisjorg
9 Replies

8. Shell Programming and Scripting

Looping through pairs of files with awk

Hi all, please help me construct the command. i want to loop through all files named bam* and bed*. My awk works for a particular pair but there are too many pairs to do manually. I have generated multiple files in a folder in a given pattern. The files are named like bam_fixed1.bam... (2 Replies)
Discussion started by: newbie83
2 Replies

9. Shell Programming and Scripting

Help on looping using awk

I have the data like this: PONUMBER,SUPPLIER,LINEITEM,SPLITLINE,LINEAMOUNT,CURRENCY IR5555,Supplier1,1,1,83.1,USD IR5555,Supplier1,1,3,40.4,USD IR5555,Supplier1,1,6,54.1,USD IR5555,Supplier1,1,8,75.1,USD IR5556,Supplier2,1,1,41.1,USD IR5556,Supplier2,1,3,43.1,USD ... (3 Replies)
Discussion started by: jeffreybsu
3 Replies

10. Shell Programming and Scripting

awk nested looping?

I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk. The text file has a organization like so: Name Date Status Location (city, state, zip fields) Where each of these is on a separate line in... (1 Reply)
Discussion started by: kellyanneghj
1 Replies
CUBRID_FETCH_ARRAY(3)							 1						     CUBRID_FETCH_ARRAY(3)

cubrid_fetch_array - Fetch a result row as an associative array, a numeric array, or both

SYNOPSIS
array cubrid_fetch_array (resource $result, [int $type = CUBRID_BOTH]) DESCRIPTION
The cubrid_fetch_array(3) function is used to get a single row from the query result and returns an array. The cursor automatically moves to the next row after getting the result. PARAMETERS
o $result -$Result comes from a call to cubrid_execute(3) o $type -Array type of the fetched result CUBRID_NUM, CUBRID_ASSOC, CUBRID_BOTH. If you need to operate the lob object, you can use CUBRID_LOB. RETURN VALUES
Returns an array of strings that corresponds to the fetched row, when process is successful. FALSE, when there are no more rows; NULL, when process is unsuccessful. The type of returned array depends on how type is defined. By using CUBRID_BOTH (default), you'll get an array with both associative and number indices, and you can decide which data type to use by setting the $type argument. The $type variable can be set to one of the fol- lowing values: oCUBRID_NUM : Numerical array (0-based) oCUBRID_ASSOC : Associative array oCUBRID_BOTH : Numerical & Associative array (default) EXAMPLES
Example #1 cubrid_fetch_array(3) example <?php $conn = cubrid_connect("localhost", 33000, "demodb"); $req = cubrid_execute($conn, "SELECT name,area,seats,address FROM stadium WHERE nation_code='GRE' AND seats > 10000"); printf("%-40s %-10s %-6s %-20s ", "name", "area", "seats", "address"); while ($row = cubrid_fetch_array($req, CUBRID_NUM)) { printf("%-40s %-10s %-6s %-20s ", $row[0], $row[1], $row[2], $row[3]); } // if you want to operate LOB object, you can use cubrid_fetch_array($req, CUBRID_NUM | CUBRID_LOB) cubrid_close_request($req); cubrid_disconnect($conn); ?> The above example will output: name area seats address Panathinaiko Stadium 86300.00 50000 Athens, Greece Olympic Stadium 54700.00 13000 Athens, Greece Olympic Indoor Hall 34100.00 18800 Athens, Greece Olympic Hall 52400.00 21000 Athens, Greece Olympic Aquatic Centre 42500.00 11500 Athens, Greece Markopoulo Olympic Equestrian Centre 64000.00 15000 Markopoulo, Athens, Greece Faliro Coastal Zone Olympic Complex 34650.00 12171 Faliro, Athens, Greece Athens Olympic Stadium 120400.00 71030 Maroussi, Athens, Greece Ano Liossia 34000.00 12000 Ano Liosia, Athens, Greece SEE ALSO
cubrid_execute(3), cubrid_fetch(3), cubrid_fetch_row(3), cubrid_fetch_assoc(3), cubrid_fetch_object(3). PHP Documentation Group CUBRID_FETCH_ARRAY(3)
All times are GMT -4. The time now is 01:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy