How to put for loop in nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to put for loop in nawk
# 1  
Old 11-22-2008
How to put for loop in nawk

Hello All,

How i can put loop in nawk. what i want is that i define a variable which contain vlaues like var='1 2 3 4 5' and then define for loop which gives vlaue to nawk one by one to varilable inside nawk and then print it.

Code:
cat /omp-data/logs/5etr/081121.APX | nawk -v CDNLIST='700 701' '

BEGIN {
for LIST in $CDNLIST
do
        TG=$LIST;
        printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR
NTWCONG\n");
done
}

Regards,
Waqas Ahmed
# 2  
Old 11-22-2008
An example:

Code:
awk -v var="1 2 3 4 5" '
BEGIN {
  split(var, arr)
  for(i in arr){
    print arr[i]
  }
}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. UNIX for Dummies Questions & Answers

Loop in Nawk Script

I have a script which performs a getline (customer enters data) and a list is returned which has the data that was entered return to them. Then it ends. How can I get this script to return to the begin and ask the question again. Ths script needs to stop after the list is returned and then hit... (2 Replies)
Discussion started by: Morph797
2 Replies

3. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

4. Shell Programming and Scripting

Noob stuck - where do I put my loop

I'm a noob working on a script to take 3 user inputs. One of them is simply a variable: "poolname". The other 2 are cases: "groupa/groupb" and "enable/disable". "groupa" and "groupb" reference 2 files - groupa.txt or groupb.txt. These files simply consist of a list of server IP addresses and port... (2 Replies)
Discussion started by: *nixnoob
2 Replies

5. Shell Programming and Scripting

How to put html frames in for loop in perl?

Hi, I have to insert html frames in for loop. Here is the code. for($k=0;$k<3;$k++) { print<<HTML; <html> <head> <title> HTML Horizontal Frames </title> </head> <frameset cols="25%,75%"> <frame src="a.html"> <frame src="b.html"> </frameset> (0 Replies)
Discussion started by: vanitham
0 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

7. Shell Programming and Scripting

how can i put the condition in for loop for the below.

i have the equation like below 07:35:07 ( AB : 2319f.ab * 22) + ( AB : 2320f.ab * 22.03 ) + ( AB :2321f.ab * 22.07 ) ...... N i want put ":" as a delimiter and break the equation like below 2319f.ab * 22 2320f.ab *22.03 2321f.ab * 22.07 . . N i know the number of... (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Shell Programming and Scripting

Sed,nawk for inputfile and out put file same

Hi, I am using sed and nawk command for replace/add/remove on file records. But when I am using the inputfile name and directing output to the same inpu name file becomes empty. I don't want to use to copy it to another file and move it back to original file. Example: sed 's/./,&/17'... (2 Replies)
Discussion started by: svenkatareddy
2 Replies

9. UNIX for Dummies Questions & Answers

What condition to be put in the while loop?

i have got a file where the env command is appended 5 times. i have to now look for the username and display it in the form of 1) PWD=/home/lee.ballancore 2) USER=lee.ballancore 3) MAIL=/var/spool/mail/lee.ballancore 4) LOGNAME=lee.ballancore 5) HOME=/home/lee.ballancore 6)... (1 Reply)
Discussion started by: nehaquick
1 Replies

10. UNIX for Dummies Questions & Answers

Passing a for loop variable into nawk

After searching through books and the internet for days I can't seem to find an example of this. I'm trying to pass a variable from a for loop into nawk but can't seem to get all the syntax right. my script (thanks to anbu23 for nawk help) is this: for customers in `cat customers.txt` do... (3 Replies)
Discussion started by: Ant1815
3 Replies
Login or Register to Ask a Question