The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-28-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Quote:
Originally Posted by royalibrahim View Post
But, what does 1 serve here or what is the role/purpose of 1?
Anyway, the default action of awk is to print the record right, even if the 'print' statement is missing?
Don't take everything for granted.
Code:
$ echo 'foo' | awk '/foo/'            #default action
foo

$ echo 'foo' | awk '/foo/{print}'     #defined action
foo
$ echo 'foo' | awk '/foo/{$1="bar"}'  #defined action

$ echo 'foo' | awk '/foo/{print}1'    #defined action and default action
foo
foo

$ echo 'foo' | awk '/foo/{$1="bar"}1'
bar