Register
It is currently Sun Apr 22, 2018 9:54 pm

Hint on FNR syntax in awk[solved]


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Apr 02, 2016 5:41 am   

Joined: Tue Mar 29, 2016 9:48 am
Posts: 26
Dear all
What is the meaning of 1 in the
Code:
$ awk ' FNR==2{$6="blah"}1' input.txt

I want to change field 6 in record 2 to blah. It works. But when I change 1 to any number, the result is the same.


Last edited by sergui on Sat Apr 02, 2016 12:40 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Sat Apr 02, 2016 7:33 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
The basic building blocks of an awk program are
<pattern><action>

This program consists of two of these blocks:
FNR==2{$6="blah"} where FNR==2 is the pattern and the bracketed expression is the action.

The second block ommits the action and hence defaults to print $0
This default action might differ from version to version. gawk should print the entire line.
And the pattern has a constant expression 1 only.


Top
 Profile  
 PostPosted: Sat Apr 02, 2016 12:39 pm   

Joined: Tue Mar 29, 2016 9:48 am
Posts: 26
Very Thanks uhelp.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP