use a mathematical expression in an awk statement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers use a mathematical expression in an awk statement
Prev   Next
# 1  
Old 06-13-2009
use a mathematical expression in an awk statement

I have some geometric data (X Y) that is in the wrong scale. My raw data is in mills but it needs to be in tenths of a mil

I am pretty familiar with awk and sed

I want to use awk to divide $1 and $2 by .1
I'm just not sure of the syntax $1 and $2 are variables and .1 is fixed

simple math would be -4610.20/.1 = -46102

I need this ...

48.00 -4610.20 J1.3 PREFERRED;

to become this ...

480 -46102 J1.3 PREFERRED;

I have written a small script to turn this ...
| UNNAMED_16_CAPACITOR_I208_B | | 1 | Pin(J1.3) | 62.20 | 348.00,-4610.20 | UNNAMED_16_CAPACITOR_I178_A | |

into this
48.00 -4610.20 J1.3 PREFERRED;

awk '$7~/\Pin/{print $11, $7" PREFERRED;"}' NP119432r2.rpt > tpa
awk '$6~/\Pin/{print $10, $6" PREFERRED;"}' NP119432r2.rpt > tpb
cat tp tpa tpb > tp_all
sed s/,/" "/ tp_all > tp1
sed s/Pin\(/" "/ tp1 > tp2
sed s/\)/" "/ tp2 > tp3

I would call this an awk question from the brain dead at this point.

Thanks,

John
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If statement fails with integer expression expected

Below is what i have in my script. htcount=$(curl -s --user tomcatstatus:tomcatstatus http://`hostname`.mypc.com:887/manager/jmxproxy?qry=Catalina:type=ThreadPool,name=\"http-nio-887\" |grep sBusy | cut -d ' ' -f2) echo $htcount if ; then echo "more than 10" else echo "Less than 10" fi... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Translate bash mathematical calculation to awk

this code below is very useful in calculating mean and quartiles. however, i would really like to translate it to awk without having to write to any external file: #!/bin/sh filename="tmp.txt" sort -n $1 >$filename rows=`wc -l $filename|cut -d' ' -f1` q2=`echo "($rows+1)/2" |bc` ... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

How To Perform Mathematical Operation Within If in awk?

Hi All, I am using an awk script as below: awk -F'|' 'BEGIN{OFS="|";} { if ($1==$3 && $3==$7 && $7==$13 && $2==$6 && $6==$11 && $15-$14+1==$11) print $0"|""TRUE"; else print $0"|""FALSE"; }' tempfile.txt In above script, all conditions are being checked except the one which is... (4 Replies)
Discussion started by: angshuman
4 Replies

5. Shell Programming and Scripting

awk regular expression

Hello, I have big files which I wanna filter them based on first column. first column should be one of these strings: chr2L || chr2R || chr3L || chr3R || chr4 || chrX and something like chr2Lh or chrY or chrM3L is not accepted. I used the following command: awk '{ if ($1=="chr2L" ||... (5 Replies)
Discussion started by: @man
5 Replies

6. Shell Programming and Scripting

incorporating a regular expression statement in a shell script (.sh)

I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced. Basically apply the follwoing regular expression: :%s/://g to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

Using Logical Expression in an AWK statement

I'm would to create a script that would give me the results below. Please note the spaces in the log file are actually commas(",".) Log file Data 0:00 21:15 899 43 31 12 25.39 0:00 21:20 736 34 19 15 35.39 0:00 21:20 776 41 28 13 ... (3 Replies)
Discussion started by: ravzter
3 Replies

8. Shell Programming and Scripting

Regular expression inside case statement notworking

I have the following script: For catching errors like: But the regular expression ERROR*memory inside case doesn't seem to be working. The output of bash -x scriptname is: Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies

9. UNIX for Dummies Questions & Answers

Awk inside Awk expression

Hi, It can be used awk inside other Awk?. I need to get another text processing while other text process. Thank you. (2 Replies)
Discussion started by: pepeli30
2 Replies

10. Shell Programming and Scripting

awk and regular expression

Ive got a file with words and also numbers. Bla BLA 10 10 11 29 12 89 13 35 And i need to change "10,29,89,25" and also remove anything that contains actually words... (4 Replies)
Discussion started by: maskot
4 Replies
Login or Register to Ask a Question