|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Displaying field of NR, not the line #
Within AWK, how do you display a field of NR? Here's my code: Code:
awk '(NR>1) && (P1=$1-w)>=100000 {print "increase of" " " P1*.0000179," " "kW at" " " 'NR*60/431900' " " "minutes" "\n" "change from" " " 'NR-10($1)' " " "kW to" " " 'NR+70($1)' "\n"}{w=$1}' filenameI can change NR and print line #'s, but cannot get a field to print...the error comes at the segment Code:
'NR-10($1)' " " "kW to" " " 'NR+70($1)' |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Quote:
)You can directly use NR. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Code:
awk '(NR>1) && (P1=$1-w)>=100000 {print "increase of " P1*.0000179 " kW at " NR*60/431900 " minutes\nchange from " NR-10($1) " kW to " NR+70($1) "\n"}{w=$1}' filenameWhich after throwing away the strings from the print statement, leaves 4 expressions to be evaluated and printed: P1*.0000179 , NR*60/431900 , NR-10($1) , and NR+70($1) . The first two of these are valid expressions in awk; the last two are not. What were you expecting those expressions to do? Without having a sample of your input file, an example of the output you expect to produce, and a description of what you're trying to do; there isn't any way that we can help correct your code. |
|
#4
|
|||
|
|||
|
To answer your question directly, $ is the 'column' operator in awk.
$(1+1) gets you column 2. $VARIABLE gets you the column number given by the variable. So, $NR. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Displaying the first field if the second field matches the pattern using Perl | royalibrahim | Shell Programming and Scripting | 7 | 11-06-2012 11:52 AM |
| sed to replace a field from a line with another field | vivek d r | Shell Programming and Scripting | 1 | 04-13-2012 10:57 AM |
| Compare Field in Current Line with Field in Previous | moutaye | Shell Programming and Scripting | 9 | 03-27-2012 05:18 AM |
| Displaying a field completely | polavan | Shell Programming and Scripting | 3 | 12-07-2011 08:01 AM |
| Displaying lines of a file where the second field matches a pattern | LordJezoX | Shell Programming and Scripting | 3 | 05-20-2009 08:00 AM |
|
|