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 11:56 AM
How to remove trailing spaces mahek_bedi UNIX for Dummies Questions & Answers 2 08-10-2007 08:21 AM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 03:23 PM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 11:48 PM
re: removing trailing space from lines oombera Shell Programming and Scripting 1 06-19-2003 11:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-26-2008
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
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'

  #2 (permalink)  
Old 10-26-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,439
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
  #3 (permalink)  
Old 10-28-2008
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
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 05:34 AM..
  #4 (permalink)  
Old 10-28-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,439
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

  #5 (permalink)  
Old 10-29-2008
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
Thanks danmero, I got the essence !! hat's off
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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