Sponsored Content
Top Forums UNIX for Dummies Questions & Answers arithmetic operation on two columns Post 302191630 by Jenny.palmy on Saturday 3rd of May 2008 08:36:20 PM
Old 05-03-2008
arithmetic operation on two columns

Hi, All,

I have a file, its content is as follows:

100 150
120 135
140 170

I want to insert a column, its content is determined by the difference between the two values in the same line, if the difference is less than 20, the new value is 1, otherwise is 0.
after the operation, the file looks like

100 150 0
120 135 1
140 170 0

Could anybody help me out? Thanks in advance.

Jenny
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple arithmetic operation

I have no idea why I can't get this to work, if anybody can help i would appreciate it. #!/bin/bash x=`cat counter.txt | wc -l` y= '$x / 7' printf "%d People have visited this page" $y :confused: (2 Replies)
Discussion started by: paladyn_2002
2 Replies

2. Shell Programming and Scripting

Help with arithmetic operation

I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated. #!/bin/sh... (3 Replies)
Discussion started by: emjayshaikh
3 Replies

3. Shell Programming and Scripting

How to perform arithmetic operation on date

Hi all, I would appreciate if anyone knows how to perform adding to date. As for normal date, i can easily plus with any number. But when it comes to month end say for example 28 Jun, i need to perform a plus with number 3, it will not return 1 Jul. Thanks in advance for your help. (4 Replies)
Discussion started by: agathaeleanor
4 Replies

4. Shell Programming and Scripting

Arithmetic operation with awk

I have output like following in a file usmtnz-dinfsi19 72 71 38 1199 1199 0.8 19:23:58 usmtnz-dinfsi19 72 71 38 1199 1199 0.8 19:24:04 (9 Replies)
Discussion started by: fugitive
9 Replies

5. Shell Programming and Scripting

Arithmetic operation between columns using loop variable

Hi I have a file with 3 columns. say, infile: 1 50 68 34 3 23 23 4 56 ------- ------- I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561)) I am doing like this: for ((i=1; i<=3; i++)) do a=`echo... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies

6. Shell Programming and Scripting

floating point arithmetic operation error

I am writing a script in zsh shell, it fetchs a number from a file using the awk command, store it as a variable, which in my case is a small number 0.62000. I want to change this number by multiplying it by 1000 to become 620.0 using the command in the script var2=$((var1*1000)) trouble is... (2 Replies)
Discussion started by: piynik
2 Replies

7. UNIX for Dummies Questions & Answers

Basic arithmetic operation with awk?

input: Name|Operation rec_10|1+2+2- Output: rec_10|1 Basically I am trying to calculate the result of "the path" in $3 where the operators follow the number and not preceding them like we normally do: rec_10: +1+2-2=1 But I realise (I am sure there is a good reason for that) that awk... (7 Replies)
Discussion started by: beca123456
7 Replies

8. Shell Programming and Scripting

Arithmetic operation in variable

Hi, Here is the script i try to perform arithmetic operation in two variables . git branch -r | while read brname ; do REV_COMMITS=`git rev-list --count $brname` echo "$brname has $REV_COMMITS" (( TOTAL = TOTAL + REV_COMMITS )) echo "in loop" $TOTAL done echo "total is " $TOTAL ... (3 Replies)
Discussion started by: greet_sed
3 Replies

9. Shell Programming and Scripting

Using awk to do arithmetic operation

Hi, I've this following text file FileVersion = 1.03 Filetype = meteo_on_curvilinear_grid TIME = 0 hours since 2016-10-03 12:00:00 +00:00 -6.855 -6.828 -6.801 -6.774 -6.747 -6.719 -6.691 -6.663 -6.634 -6.606 -6.577 -6.548 -6.519 -6.489 TIME = 0 hours since... (2 Replies)
Discussion started by: xisan
2 Replies

10. How to Post in the The UNIX and Linux Forums

How to get defined precision after arithmetic operation using syncsort?

I have to do some arithmetic operation on Field 8 which is calculated by Field 9/Field 7 Suppose i have data like : 0800123456|JAN|2017|JAN|2018|0800123456|0|0.0000|0.00| 0800234567|JAN|2017|JAN|2018|0800234567|4|2.5812|10.32| 0800666666|JAN|2017|JAN|2018|0800666666|2|1.7255|3.45|... (0 Replies)
Discussion started by: pumrao
0 Replies
ASCII(7)						 Miscellaneous Information Manual						  ASCII(7)

NAME
ascii - the ASCII character set. DESCRIPTION
The ASCII character set is as follows: |000 nul|001 soh|002 stx|003 etx|004 eot|005 enq|006 ack|007 bel| |010 bs |011 ht |012 nl |013 vt |014 np |015 cr |016 so |017 si | |020 dle|021 dc1|022 dc2|023 dc3|024 dc4|025 nak|026 syn|027 etb| |030 can|031 em |032 sub|033 esc|034 fs |035 gs |036 rs |037 us | |040 sp |041 ! |042 " |043 # |044 $ |045 % |046 & |047 ' | |050 ( |051 ) |052 * |053 + |054 , |055 - |056 . |057 / | |060 0 |061 1 |062 2 |063 3 |064 4 |065 5 |066 6 |067 7 | |070 8 |071 9 |072 : |073 ; |074 < |075 = |076 > |077 ? | |100 @ |101 A |102 B |103 C |104 D |105 E |106 F |107 G | |110 H |111 I |112 J |113 K |114 L |115 M |116 N |117 O | |120 P |121 Q |122 R |123 S |124 T |125 U |126 V |127 W | |130 X |131 Y |132 Z |133 [ |134 |135 ] |136 ^ |137 _ | |140 ` |141 a |142 b |143 c |144 d |145 e |146 f |147 g | |150 h |151 i |152 j |153 k |154 l |155 m |156 n |157 o | |160 p |161 q |162 r |163 s |164 t |165 u |166 v |167 w | |170 x |171 y |172 z |173 { |174 | |175 } |176 ~ |177 del| |00 nul|01 soh|02 stx|03 etx|04 eot|05 enq|06 ack|07 bel| |08 bs |09 ht |0A nl |0B vt |0C np |0D cr |0E so |0F si | |10 dle|11 dc1|12 dc2|13 dc3|14 dc4|15 nak|16 syn|17 etb| |18 can|19 em |1A sub|1B esc|1C fs |1D gs |1E rs |1F us | |20 sp |21 ! |22 " |23 # |24 $ |25 % |26 & |27 ' | |28 ( |29 ) |2A * |2B + |2C , |2D - |2E . |2F / | |30 0 |31 1 |32 2 |33 3 |34 4 |35 5 |36 6 |37 7 | |38 8 |39 9 |3A : |3B ; |3C < |3D = |3E > |3F ? | |40 @ |41 A |42 B |43 C |44 D |45 E |46 F |47 G | |48 H |49 I |4A J |4B K |4C L |4D M |4E N |4F O | |50 P |51 Q |52 R |53 S |54 T |55 U |56 V |57 W | |58 X |59 Y |5A Z |5B [ |5C |5D ] |5E ^ |5F _ | |60 ` |61 a |62 b |63 c |64 d |65 e |66 f |67 g | |68 h |69 i |6A j |6B k |6C l |6D m |6E n |6F o | |70 p |71 q |72 r |73 s |74 t |75 u |76 v |77 w | |78 x |79 y |7A z |7B { |7C | |7D } |7E ~ |7F del| ASCII(7)
All times are GMT -4. The time now is 08:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy