Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Displaying field of NR, not the line # Post 302740891 by Don Cragun on Friday 7th of December 2012 04:25:05 AM
Old 12-07-2012
Quote:
Originally Posted by markymarkg123
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}' filename

I 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)'

Your awk program (after unneeded quote removal) is:
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}' filename

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

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

displaying the first line?

how do i display just the first line of a file with the cat command or any command for that matter (4 Replies)
Discussion started by: imuuk
4 Replies

2. UNIX for Dummies Questions & Answers

displaying the last line of the file

hi... i need to display the last line of the file and capture the line in to a variable in unix envt.(not the perl ones)... please help (8 Replies)
Discussion started by: lmadhuri
8 Replies

3. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

4. Shell Programming and Scripting

Displaying a field completely

Version: AIX 6.1 (korn shell) In the below output, the field with the heading 'Address' has some names like hwproc214-priv1.gnas.wrd.netwhich are only partially displayed. $ netstat -i Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll en2 1500 link#2 ... (3 Replies)
Discussion started by: polavan
3 Replies

5. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

6. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

7. Shell Programming and Scripting

Displaying the first field if the second field matches the pattern using Perl

Hi, I am trying with the below Perl command to print the first field when the second field matches the given pattern: perl -lane 'open F, "< myfile"; for $i (<F>) {chomp $i; if ($F =~ /patt$/) {my $f = (split(" ", $i)); print "$f";}} close F' dummy_file I know I can achieve the same with the... (7 Replies)
Discussion started by: royalibrahim
7 Replies

8. Red Hat

Displaying command return in one line

Hello all I have a query (SQL) that returns a rather long field from an Oracle database. The field in question is defined on 400 characters but all these 400 cannot be displayed by the echo command. Thus when I launch the following command: echo "SELECT FIELD01 FROM TABLE_NAME;" | sqlplus -s... (9 Replies)
Discussion started by: S. BASU
9 Replies

9. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

10. UNIX for Beginners Questions & Answers

Displaying every other line in an array.

Hi, I have an array, that works well. But, I want to have it display every other line. Like so, 1, 3, 5, 7, etc, etc. Here is the relevant code: I'm sorry for the pastebin link. For some reason, I can't get the code to format properly with the code tags. code tags work fine... everyone... (4 Replies)
Discussion started by: ignatius
4 Replies
JZIP(6) 						 John's Z-code Interpreter Program						   JZIP(6)

NAME
jzip - execute Infocom v1-5 and Inform v1-5 & v8 game files SYNOPSIS
jzip [ options ] z-file-name DESCRIPTION
jzip invokes the Z-code Interpreter. REQUIREMENTS
jzip will run under most (if not all) flavors of Unix, including AIX, Solaris, SunOS, HP/UX, Linux, Free/NetBSD, IRIX, NeXT Mach, DEC OSF/1, and others. EDITING
JZip now supports arrowkey editing in UNIX. Up/Down selects the previous / next command in history Left/Right moves the cursor over the line. Backspace deletes Typing inserts under the cursor OPTIONS
-l n lines in display -c n columns in display -r n text right margin (default = 1) -t n text top margin (default = 0) -v display version information -m monochrome mode -y set Tandy bit -s n zmachine strict level, from 0 (none), 1 (report once, recommended) to 3. ENVIRONMENT
jzip looks for the environment variable INFOCOM_PATH and will use the path found there to look for the story file specified on the command line if the story file cannot be found in the current directory. CREDITS
jzip is written and maintained by John Holder (j-holder@home.com), based on the ZIP v2.0 sources by Mark Howell and Olaf 'Olsen' Barthel. AVAILABILITY
The most recent version of jzip can be downloaded from one of: http://www.jzip.sourceforge.net/ ftp://ifarchive.org/infocom/interpreters/zip/ FILES
/usr/games/jzip The Z-Code Interpreter Program /usr/lib/games/zfiles Recommended location for Zcode files RELATED USENET NEWSGROUPS
Interactive Fiction (IF) authors should check out rec.arts.int-fiction, and IF players should check out rec.games.int-fiction. 2.1 JZIP(6)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy