Sponsored Content
Top Forums Shell Programming and Scripting Dividing values within rows with awk? Post 302929351 by Corona688 on Friday 19th of December 2014 04:53:24 PM
Old 12-19-2014
Yes, that's absolutely fine to do. Watch out for $2 being zero, that would crash the program.

Code:
$ awk '$2 != 0 { print $1/$2 }' <<EOF
1 2
3 4
5 6
EOF

0.5
0.75
0.833333

$

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Dividing float values

Hi I know its a dumb question but can any one please explain me the difference of executing a shell script in the following 2 ways. . script.sh sh script.sh I have a problem if I execute the following code as sh script.sh DB_CNT_ALW=0.20 SCT_VAR=0.05 if ; then echo "== Difference... (3 Replies)
Discussion started by: shash
3 Replies

2. Shell Programming and Scripting

plus values from two files in differient rows

Hi Guys :), I have two files. filea: 12:20:23 4 12:21:23 3 12:22:23 2 12:25:23 3 fileb: 11:20:23 4 12:21:23 3 12:22:23 2 12:26:23 3 12:30:23 3 The result will be: 11:20:23 4 12:20:23 4 (3 Replies)
Discussion started by: jimmy_y
3 Replies

3. Shell Programming and Scripting

How to consolidate values in one column from different rows into one?

Hi Guys, Thank you all for helping me with my different queries and I continue to get better at scripting because of help from all of you! I have a file that would look something like - ID SUB ID VALUE 1 10 5 2 18 7 1 ... (1 Reply)
Discussion started by: sncoupons
1 Replies

4. UNIX for Dummies Questions & Answers

Comparing two files and dividing the values

Hi all, I am new to unix and I am trying hard to get this requirement, but no luck. I am trying to compare two cloumns in two files and if it matches, the last column in file1 must be divided by file2 and the output must be written in a new file. To elaborate the 2nd column in file1 (EUR) must be... (6 Replies)
Discussion started by: smadderla
6 Replies

5. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

6. Shell Programming and Scripting

Remove rows with e column values

Hi All, I have a big file with 232 columns and 9 million rows, I want to delete all rows with same column values in col3 through col232. Also the output should be sorted based on first 2 columns. Here is a reduced example with 6 columns. I want to remove rows with duplicate values in col3... (9 Replies)
Discussion started by: alpesh
9 Replies

7. Shell Programming and Scripting

Average values of duplicate rows

I have this file input.txt. I want to take average column-wise for the rows having duplicate gene names. Gene Sample_1 Sample_2 Sample_3 gene_A 2 4 5 gene_B 1 2 3 gene_A 0 5 7 gene_B 4 5 6 gene_A 11 12 13 gene_C 2 3 4 Desired output: gene_A 4.3 7 8.3 gene_B 2.5 3.5 4.5 gene_C 2 3 4... (6 Replies)
Discussion started by: Sanchari
6 Replies

8. Shell Programming and Scripting

Summing up values of rows of numbers

data file contains failed=24 error=23 error=163 failed=36 error=903 i need to get a total count of each value above. i'm looking for the most efficient method to do this as the datafile i provided is just a sample. the actual data can be several hundred thousands of lines. so from... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. UNIX for Beginners Questions & Answers

Pivoting values from column to rows

I/P: I/P: 2017/01/01 a 10 2017/01/01 b 20 2017/01/01 c 40 2017/02/01 a 10 2017/02/01 b 20 2017/02/01 c 30 O/P: a b c 2017/01/01 10 20 40 2017/02/01 10 20 30 (18 Replies)
Discussion started by: Booo
18 Replies

10. UNIX for Beginners Questions & Answers

Compare values in multiple rows in one column using awk

I would like to compare values in column 8, and grep the ones where the different is > 1, columns 1 and 2 are the key for array. Every 4 rows the records values in columns 1 and 2 changed. Then, the comparison in the column 8 need to be done for the 4 rows everytime columns 1 and 2 changed ... (4 Replies)
Discussion started by: jiam912
4 Replies
Config::Watch(3pm)					User Contributed Perl Documentation					Config::Watch(3pm)

NAME
Log::Log4perl::Config::Watch - Detect file changes SYNOPSIS
use Log::Log4perl::Config::Watch; my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", check_interval => 30, ); while(1) { if($watcher->change_detected()) { print "Change detected! "; } sleep(1); } DESCRIPTION
This module helps detecting changes in files. Although it comes with the "Log::Log4perl" distribution, it can be used independently. The constructor defines the file to be watched and the check interval in seconds. Subsequent calls to "change_detected()" will o return a false value immediately without doing physical file checks if "check_interval" hasn't elapsed. o perform a physical test on the specified file if the number of seconds specified in "check_interval" have elapsed since the last physical check. If the file's modification date has changed since the last physical check, it will return a true value, otherwise a false value is returned. Bottom line: "check_interval" allows you to call the function "change_detected()" as often as you like, without paying the performing a significant performance penalty because file system operations are being performed (however, you pay the price of not knowing about file changes until "check_interval" seconds have elapsed). The module clearly distinguishes system time from file system time. If your (e.g. NFS mounted) file system is off by a constant amount of time compared to the executing computer's clock, it'll just work fine. To disable the resource-saving delay feature, just set "check_interval" to 0 and "change_detected()" will run a physical file test on every call. If you already have the current time available, you can pass it on to "change_detected()" as an optional parameter, like in change_detected($time) which then won't trigger a call to "time()", but use the value provided. SIGNAL MODE Instead of polling time and file changes, "new()" can be instructed to set up a signal handler. If you call the constructor like my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", signal => 'HUP' ); then a signal handler will be installed, setting the object's variable "$self->{signal_caught}" to a true value when the signal arrives. Comes with all the problems that signal handlers go along with. TRIGGER CHECKS To trigger a physical file check on the next call to "change_detected()" regardless if "check_interval" has expired or not, call $watcher->force_next_check(); on the watcher object. DETECT MOVED FILES The watcher can also be used to detect files that have moved. It will not only detect if a watched file has disappeared, but also if it has been replaced by a new file in the meantime. my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", check_interval => 30, ); while(1) { if($watcher->file_has_moved()) { print "File has moved! "; } sleep(1); } The parameters "check_interval" and "signal" limit the number of physical file system checks, simililarily as with "change_detected()". COPYRIGHT AND LICENSE
Copyright 2002-2009 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-07-21 Config::Watch(3pm)
All times are GMT -4. The time now is 06:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy