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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
please explain the below mail2sant Shell Programming and Scripting 1 04-04-2008 05:04 AM
explain plz avikal Shell Programming and Scripting 2 04-03-2008 08:11 AM
Please can any one explain this ${0##/} gadege Shell Programming and Scripting 2 04-01-2008 12:26 PM
please explain this dummy_needhelp Shell Programming and Scripting 2 10-14-2007 10:17 PM
Can anyone explain plz r_W213 UNIX for Advanced & Expert Users 3 03-27-2007 01:52 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-20-2006
Registered User
 

Join Date: Sep 2005
Posts: 74
Stumble this Post!
can anyone explain this codes here?

nawk 'FNR > 3 {printf("%s%c", $0, OFS)}END{print ""}' "$1" > "$1".out && mv "$1
".out "$1"

what is FNR? or printf("%s%c",$0, OFS)}?

sorry..im lost...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-20-2006
Registered User
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
Stumble this Post!
The FNR variable contains the number of lines read, but is reset for each file read. The NR variable accumulates for all files read. Therefore if you execute an awk script with two files as arguments, with each containing 10 lines:

nawk '{print NR}' file file2
nawk '{print FNR}' file file2


the first program would print the numbers 1 through 20, while the second would print the numbers 1 through 10 twice, once for each file.


printf is used to print the output into the file instead of screen. inside the printf %s is used for string printing and %c is used for character printing. that is $0 as string and OFS is out field separator as character other then space which is default.
Reply With Quote
  #3 (permalink)  
Old 01-20-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
Joins all lines starting at line 4

FNR > 3 { ... }
Execute code ... starting at line 4 of currrent file.
Lines 1 to 3 are ignored.
FNR = The number of the current input record in the current file

printf("%s%c",$0, OFS)}
Print current input record followed by record separator (no line feed at end)
OFS = The output field separator (default is a space)

END{ ... }
Execute code ... when all input records has been read

print ""
Print only one line feed


Input file:
line1
line2
line3
line4
line5

Result file (one record length):
line4 line4
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0