Awk- Mastering "For loop"

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk- Mastering "For loop"
# 1  
Old 08-12-2011
Awk- Mastering "For loop"

Hi all

I'm trying to master awk - for loop. As I see The Awk tutorial has very less description on for loop.
for (initialization; condition; increment) body
awk '{ for (i = 1; i <= 3; i++)           print $i }'

It would be really great if you write down all techniques or tips or one liners that can do wonders or simple jobs.
So that all awk beginners like me and others can get great help.
# 2  
Old 08-12-2011
It's already done. Smilie The GNU Awk User's Guide
# 3  
Old 08-12-2011

But I'm afraid not so many examples to understand fully the power of for loop
# 4  
Old 08-12-2011
In addition to the GNU manual, this page has a good flow and some examples that might help you understand:

Awk - A Tutorial and Introduction - by Bruce Barnett
# 5  
Old 08-12-2011
looks very useful! thanx agama!
# 6  
Old 08-12-2011
awk 'BEGIN{for(;++i<11;)print i}'

# 7  
Old 08-12-2011
Also please provide brief description for new beginners like me. Thanx alot!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: Performing "for" loop within text block with two files

I am hoping to pull multiple strings from one file and use them to search within a block of text within another file. File 1PS001,001 HLK PS002,004 MWQ PS004,002 RXM PS004,006 DBX PS004,006 SBR PS005,007 ML PS005,009 DBR PS005,011 MR PS005,012 SBR PS006,003 RXM PS006,003 >SJ PS006,010... (11 Replies)
Discussion started by: jvoot
11 Replies

2. Shell Programming and Scripting

Using "for" loop within "awk"

Hi Team. I am trying to execute a simple for loop within an awk but its giving a different result. Below is the main code: awk '{for(i=1;i<=6;i++) print $i}'The result should be 1 2 3 4 5 6 but its not giving this result. Can someone please help? (3 Replies)
Discussion started by: chatwithsaurav
3 Replies

3. Shell Programming and Scripting

For Loop Field editing - without using "awk"

Hi, I'm using Linux and bash shell. I have a file (F1.txt) with contents like Table1 Column1 123abc Table1 Column2 xyz Table2 Column1 543 Now, I would like to get the output as UPDATE Table1 SET Column1='123abc'; UPDATE Table1 SET Column2='xyz'; UPDATE Table2 SET Column1='543';... (3 Replies)
Discussion started by: Dev_Dev
3 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep ""|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep ""|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

Printing "END" before a new loop in AWK

First off, I have been learning AWK by trial and error over the last week or so, and there are some gaps in my basic understanding of the language. Here is my situation: I am coding and outputting results from an experiment I conducted in Psyscope, which has all been compiled into a master file.... (2 Replies)
Discussion started by: ccox85
2 Replies
Login or Register to Ask a Question