LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2003, 07:30 AM   #1
realos
Member
 
Registered: Jul 2002
Location: Germany
Distribution: Redhat 7.3, Debian 3.1, Knoppix 3.1, Ubuntu 6.10
Posts: 113

Rep: Reputation: 15
Question help with "next" command in "awk"


I am new to awk and have seen some coding in awk with "next" appearing at the end of the actions like;

/EXPRESSION/ { variable=5; next}
/EXPRESSION2/ {variable2=6; next}

I was wondering if it would make a difference when I left out the next commands?

I know that next makes awk read the next line and start with the script from beginning, but exactly that happens even if I leave out "next", right?



thank in anticipation for your ideas.

Last edited by realos; 05-14-2003 at 04:09 AM.
 
Old 05-13-2003, 10:42 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: help with "next" command in "awk"

Quote:
I was wondering if it made a difference when I left out the next commands?

I know that next makes awk read the next line and start with the script from beginning, but exactly that happens even if I leave out "next", right?
The script will continue using the same line of input text.

So, using your example
Code:
/EXPRESSION/ { variable=5; next}
/EXPRESSION2/ {variable2=6; next}
Say, the current line of text matches EXPRESSION. Then the next line of text will be read, on which the script will start processing from the start.

So the second line of code will not be executed when EXPRESSION matches the current line. Thus variable2 will never be assigned 6, even if EXPRESSION2 matches the same line.

If this script is the whole script, "next" in the last line of code will not make a difference, as after executing the last line of the script, awk will start the script from the start on the next line of text anyways.

Last edited by Hko; 05-13-2003 at 10:44 AM.
 
Old 05-13-2003, 03:34 PM   #3
realos
Member
 
Registered: Jul 2002
Location: Germany
Distribution: Redhat 7.3, Debian 3.1, Knoppix 3.1, Ubuntu 6.10
Posts: 113

Original Poster
Rep: Reputation: 15
Hko,

thanks for reply. You are right the "next" in second line would not make sense if it was the whole script. But I am going through a bigger script and just quoted the appropriate lines.

Now, I got the idea. thanks again... and stay cool
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration