Sponsored Content
Full Discussion: nawk is truncating output
Top Forums Shell Programming and Scripting nawk is truncating output Post 302714951 by sdosanjh on Saturday 13th of October 2012 08:46:30 AM
Old 10-13-2012
nawk is truncating output

Legends,

I have 2 files f1 and f2. when i use nawk to compare the difference(subtraction) from 4th column of the file, it truncates the output.
can you please help to resolve this.

subtraction is (4th col of f1 - 4th col of f2). but it gives only below lines out of 116. I want to print all the lines of the file even if there is diff or no diff. Smilie

Code:
san:/tmp> wc -l f1 f2 | grep -v total
     116 f1
     116 f2

san:/tmp> head -3 f1 f2
==> f1 <==
TSCparser1 1irons1 EMEA_01 3
TSCparser12 1irons1 SPAIN_01 0
TSCparser13 1irons1 GERMANY_03 0

==> f2 <==
TSCparser1 1irons1 EMEA_01 3
TSCparser12 1irons1 SPAIN_01 0
TSCparser13 1irons1 GERMANY_03 0

san:/tmp> nawk 'FNR==NR{a[$1,$2,$3]=$4;next}{if(a[$1,$2,$3]){print $1,$2,$3,(a[$1,$2,$3]-$4)" times gapped in past 1 hr."}}' OFS="         " f1 f2
TSCparser1         1irons1         EMEA_01         0 times gapped in past 1 hr.
TSCparser94         1irons1         LSE_01         0 times gapped in past 1 hr.
TSCparser43         4irons1         STUTTGART_04         0 times gapped in past 1 hr.
TSCparser44         4irons1         STUTTGART_05         0 times gapped in past 1 hr.
TSCparser46         4irons1         STUTTGART_07         0 times gapped in past 1 hr.
TSCparser47         4irons1         STUTTGART_08         0 times gapped in past 1 hr.

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning nawk output to variables

I do a lot of command line scripting to capture data from files or other command output. I've checked in a number of Unix and scripting books but for the life of me I can't find out how to asign field data from nawk output into variables that I can manipulate later. For example, reading a two... (6 Replies)
Discussion started by: steveje0711
6 Replies

2. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

3. Shell Programming and Scripting

Truncating a variable

I have a variable that is a full path name and I just want the file name with out the extension. I have figured out how to do this using some temp files but I would really like to avoid that if possible. I know I can do echo ${TMPNAME%.*} to drop the extension is there a similar way to drop... (3 Replies)
Discussion started by: whdr02
3 Replies

4. Shell Programming and Scripting

help me how to use nawk for required output

Hi all i have 2 input files 1st file is N1 | N2|N3|N4|N5|N6|N7|N8|N9 4041491000|245160|1|0|0|1|0|0|0 4041401505|152178|1|1|1|1|0|0|0 4041450004|014052|1|1|1|1|0|0|0 4041450005|580916|1|1|1|1|0|0|0 4041491000|230990|1|0|1|1|0|0|0 4041460001|338317|1|1|1|1|0|0|0 2nd file N1 |... (8 Replies)
Discussion started by: dodasajan
8 Replies

5. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there. I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies

6. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

7. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

8. Shell Programming and Scripting

Nawk command to output in var

Hi I have this command, which counts number of lines in a specific file and then prints it on screen.nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename I would like to have the output put into a variable, but can't seem to find the correct argument for it. How do I... (3 Replies)
Discussion started by: bulleteyedk
3 Replies

9. UNIX for Dummies Questions & Answers

awk truncating first field output?

Hello, I'm writing an Awk script to take a command line argument (student's name) and output their relevant student#, name, and marks. For some reason, awk arbitrarily removes the first digit from the student number and doesn't show me the proper output. Here is my code: #! /usr/bin/awk -f... (6 Replies)
Discussion started by: trashmouth12
6 Replies

10. Solaris

How to avoid truncating in ps output ?

Hello, This is Solaris 10 (x86) bash-3.2# cat /etc/release Solaris 10 5/09 s10x_u7wos_08 X86 Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms. Assembled 30 March... (5 Replies)
Discussion started by: solaris_1977
5 Replies
times(3)						     Library Functions Manual							  times(3)

NAME
times - Gets process and child process times LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <sys/times.h> clock_t times( struct tms *buffer); Programs that are being developed for conformance to the AT&T System V Interface Definition must specify two #include statements, as fol- lows: #include <sys/types.h> #include <sys/times.h> STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: times(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to type tms structure space where system time information is stored. DESCRIPTION
The times() function fills the type tms structure space pointed to by the buffer parameter with time-accounting information. All time val- ues reported by this function are in hardware-dependent clock ticks. The times of a terminated child process are included in the tms_cutime and tms_cstime elements of the parent process when a wait function returns the process ID of that terminated child. The tms structure, which is defined in the sys/times.h header file, contains the following members: User time. The CPU time charged while executing user instructions of the calling process. System time. The CPU time charged during system execution on behalf of the calling process. User time, children. The sum of the tms_utime and the tms_cutime times of the child processes. System time, children. The sum of the tms_stime and the tms_cstime times of the child processes. When a child process does not wait for its children, its child-process times are not included in its times. This information comes from the calling process and each of its terminated child processes for which a wait function has been executed. RETURN VALUES
Upon successful completion, the times() function returns the elapsed real time since an arbitrary reference time in the past (for example, system start-up time). The reference time does not change from one invocation of times() within the process to another. The elapsed times are in units of 1/CLK_TCK seconds, where CLK_TCK is processor dependent. For application portability, the value of CLK_TCK should be queried using the sysconf() function (see sysconf(3)). The return value may overflow the possible range of type clock_t values. When the times() function fails, a value of (clock_t)-1 is returned. RELATED INFORMATION
Commands: cc(1) Functions: exec(2), fork(2), getrusage(2), profil(2), stime(3), sysconf(3), time(3), wait(2) Standards: standards(5) delim off times(3)
All times are GMT -4. The time now is 01:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy