Issue with basic Awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with basic Awk script
# 1  
Old 10-08-2011
Bug Issue with basic Awk script

Here's a basic awk program I am trying to run. It shows no error but shows no result either too. If someone can look up and tell me what's wrong I will be obliged.

Thanks. Smilie

Code Snippet.

Code:
#!/bin/bash
 awk '{
     for (i = 1 ; i <= 3 ; i++)
             for ( j = 1 ; j <= 3 ; j++ ) {
                     a[i,j] = 9
         }
 }
 
 END {
     for ( i = 1 ; i <= 3 ; i++ )
             for ( j = 1 ; j <= 3 ; j++ )
                     printf(" %s ", a[i,j])
 }'

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 10-08-2011
You don't show us what output you're expecting,
do you want something like this?

Code:
zsh-4.3.12[t]% awk 'BEGIN {
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++)
      a[i,j] = 9

  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++)
      printf " %s ", a[i,j]
}'
 9  9  9  9  9  9  9  9  9 %

# 3  
Old 10-08-2011
Thanks Radoulov. That's what I need. I will now build on this my actual proble.

Thank You. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic loop awk/shell script question..

Hi, Sorry if this is a newbie question. I guess you can use either awk or shell script for this sequence of operations, but knowing very little about either of them I'm not sure how I should try to write this. The basic objective is to copy certain files that are scattered all over my... (10 Replies)
Discussion started by: pc2001
10 Replies

2. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

3. UNIX for Dummies Questions & Answers

awk script performance issue

Hello All, I have the below excerpt of code in my shell script and it taking long time to complete, though it prints the output quickly. Is there a way to make it come out once it finds the first instance as the file size of 4.7 GB it could be going through all lines of the data file to find for... (3 Replies)
Discussion started by: Ariean
3 Replies

4. Shell Programming and Scripting

Awk script searching patterns issue

Hi I am having a file like this FILE1 ##################### C16ROTINV_ REFCLK_RXL RXBCLK32_R REFCLK_TXL CLK8_TXLIN RXBCLK32_R DCLK_TXLIN CLK32D_TXL RXACLK32_R ##################### (3 Replies)
Discussion started by: jaita
3 Replies

5. Shell Programming and Scripting

AWK script issue for the part regular expression

Hi I am having a file as shown below FILE 1 TXDD00, TXDD01, TXDD02, TXDD03, TXDD04, TXDD05, TXDD06, TXDD07, TXDD08, TXDD09, TXDD10, TXDD11, TXDD12, TXDD13, TXDD14, TXDD15, TXDD16, TXDD17, TXDD18, TXDD19, TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1,... (3 Replies)
Discussion started by: jaita
3 Replies

6. Shell Programming and Scripting

cron job issue..i hav read the basic threads already...

hi friends well m facing a different sort of issue in my cron. i hav set job like this 30 09 * * 1 /bin/backup14M 01 14 * * 1 /bin/backup14N 20 18 * * 1 /bin/backup14E that is for every Monday at three different times. but, first job executes well, later ones do not. I checked my... (13 Replies)
Discussion started by: oracle.test2
13 Replies

7. Shell Programming and Scripting

Issue with awk script

Hi , I am using the below awk script awk '{if($0 ~ /B1/) {set=1; next }; if( $0 ~ /END/) {set = 0}; if (set ) { print }}' CODE | awk '/A \(P1\)/{f=1}f && /}/{print; system("cat $1");f=0;next}1' A.lib > newfile I need to insert code from CODE file into A.lib file A.lib file... (1 Reply)
Discussion started by: shalini_008
1 Replies

8. UNIX for Dummies Questions & Answers

Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk. This is the contents of test.sh awk '{print $1}' From the prompt if I enter: ./test.sh Hello World I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Discussion started by: JasonHamm
2 Replies

9. Shell Programming and Scripting

awk basic issue

Hi all, I have an awk basic question. file.text Our Location: Our home has light yellow siding, and is a duplex on Main Street, across from the High School, and across the lane from the Health Center If I run: cat file.txt | awk '{print $2}' | grep... (7 Replies)
Discussion started by: research3
7 Replies

10. Shell Programming and Scripting

Performance issue with awk script.

Hi, The below awk script is taking about 1 hour to fetch just 11 records(columns). There are about 48000 records. The script file name is take_first_uniq.sh #!/bin/ksh if then while read line do first=`echo $line | awk -F"|" '{print $1$2$3}'` while read line2 do... (4 Replies)
Discussion started by: RRVARMA
4 Replies
Login or Register to Ask a Question