The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove trailing G Heathe_Kyle Shell Programming and Scripting 3 04-14-2008 10:56 AM
How to remove trailing spaces mahek_bedi UNIX for Dummies Questions & Answers 2 08-10-2007 07:21 AM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 02:23 PM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 10:48 PM
re: removing trailing space from lines oombera Shell Programming and Scripting 1 06-19-2003 10:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-26-2008
Registered User
 

Join Date: Jun 2007
Posts: 85
awk syntax doubt - trailing 1 value

In the below awk syntax, what does the value '1' signify?

awk '{....}1' file

some eg:
Code:
awk '{gsub(/[^[:cntrl:]]/,"")}1'
awk 'BEGIN{ORS=""}1'
awk '{ORS=(!(NR%5)?"":"\n")}1'
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-26-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 901
awk evaluates the 1 as true and the prints the entire line by default, including a newline.
Code:
echo 'foo' | awk '/foo/{print}1'
Take a look here: http://sunsite.ualberta.ca/Documenta...l#SEC_Contents
Reply With Quote
  #3 (permalink)  
Old 10-28-2008
Registered User
 

Join Date: Jun 2007
Posts: 85
Quote:
Originally Posted by danmero View Post
awk evaluates the 1 as true and the prints the entire line by default, including a newline.
Code:
echo 'foo' | awk '/foo/{print}1'
Take a look here: The GNU Awk User's Guide: Table of Contents
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?

Last edited by royalibrahim; 10-28-2008 at 04:34 AM..
Reply With Quote
  #4 (permalink)  
Old 10-28-2008
danmero danmero is offline Forum Advisor  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 901
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
Reply With Quote
  #5 (permalink)  
Old 10-28-2008
Registered User
 

Join Date: Jun 2007
Posts: 85
Thanks danmero, I got the essence !! hat's off
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 10:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66