Constructing numbers from input lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Constructing numbers from input lines
# 1  
Old 01-23-2011
Constructing numbers from input lines

I have a file with the information shown and I want to capture the
entry having the rgdt tag and taking the value (the location of the represents the decimal point, for example 0p50 represents 0.50)

I then want to divide the number at the end of each line by the value 0.50

I want to do this using awk

Code:
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis  345
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 45
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 456
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 4523
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 2342
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 33425 
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw.csmis 3512

# 2  
Old 01-23-2011
Like this?

Code:
awk -F'[- \t]*' 'sub(/rgdt/,x,$4){sub(/p/,".",$4);print $7/$4}' infile

# 3  
Old 01-23-2011
the rgdt0p50 can occur in any position not necessarily $4
# 4  
Old 01-23-2011
Except the last column? only once per line?
# 5  
Old 01-23-2011
That's correct

Actual file might actually be like this. Want to strip away the first entry but remember the value in the line 0.50 where I need to divide the last number with 0.50

Code:
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:0. Rms Value    = 0.00551131
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:1. Rms Value    = 0.0105689
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:2. Rms Value    = 0.0137097
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:3. Rms Value    = 0.0163874
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:4. Rms Value    = 0.0187422
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:5. Rms Value    = 0.0197708
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:6. Rms Value    = 0.0208463
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:7. Rms Value    = 0.0217194
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:8. Rms Value    = 0.0226114
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:9. Rms Value    = 0.0229611
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:10. Rms Value    = 0.0239331
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:11. Rms Value    = 0.025327
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:12. Rms Value    = 0.0250741
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:13. Rms Value    = 0.0255705
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:14. Rms Value    = 0.0266015
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:15. Rms Value    = 0.0268534
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:16. Rms Value    = 0.0264882
npt02-z30-sr65-rgdt0p50-dc0p006-16x12drw-run1.log:17. Rms Value    = 0.0269775

Actually it would be good to store the value 0.50 and store it so I can determine 1/(0.5*0.5), then multiply
the last number by this value.

I should end up with

Code:
0. Rms Value    = 0.00551131/(0.50*0.50)
1. Rms Value    = 0.0105689/(0.50*0.50)
2. Rms Value    = 0.0137097/(0.50*0.50)
3. Rms Value    = 0.0163874/(0.50*0.50)
4. Rms Value    = 0.0187422/(0.50*0.50)
5. Rms Value    = 0.0197708/(0.50*0.50)
6. Rms Value    = 0.0208463/(0.50*0.50)
7. Rms Value    = 0.0217194/(0.50*0.50)
8. Rms Value    = 0.0226114/(0.50*0.50)
9. Rms Value    = 0.0229611/(0.50*0.50)
10. Rms Value    = 0.0239331/(0.50*0.50)
11. Rms Value    = 0.025327/(0.50*0.50)
12. Rms Value    = 0.0250741/(0.50*0.50)
13. Rms Value    = 0.0255705/(0.50*0.50)
14. Rms Value    = 0.0266015/(0.50*0.50)
15. Rms Value    = 0.0268534/(0.50*0.50)
16. Rms Value    = 0.0264882/(0.50*0.50)
17. Rms Value    = 0.0269775/(0.50*0.50)


Last edited by kristinu; 01-23-2011 at 03:23 AM..
# 6  
Old 01-23-2011
Code:
awk 'sub(/.*rgdt/,x){sub(/p/,".");sub(/-.*/,x,$1);print $NF/$1}' infile


Last edited by Scrutinizer; 01-23-2011 at 04:01 AM..
# 7  
Old 01-23-2011
At the moment I've got the following code, and need to do this additional thing, divide last number with square of the rgdt value.

Code:
          grep "Rms Value" $f.log                          \
            | awk  '{   sub(/[^:]*:[0-9]*\.[ \t]*/,x);     \
                        print $1" "$2" "$3" "$4" "$NF   \
                    }' > $f.csmis


Last edited by kristinu; 01-23-2011 at 03:33 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form: 37.68899917602539 58.07500076293945 57.79100036621094 The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2. I have tried to do this... (2 Replies)
Discussion started by: crunchgargoyle
2 Replies

2. Shell Programming and Scripting

Constructing a Matrix

Hi, I do have couple of files in a folder. The names of each of the files have a pattern. ahet_005678.txt ahet_005898.txt ahet_007678.txt ahet_004778.txt ... ... ahet_002378.txt Each of the above files have the same pattern of data with 4 columns and have an header for the last 3... (4 Replies)
Discussion started by: Kanja
4 Replies

3. UNIX for Dummies Questions & Answers

Extraction of numbers from input

I have the following input: xxxx-2.7.19_WR3 I have extract the following: 2.7.19 Can anyone suggest an awk or sed command to do the above...:confused: another condition is if the input is : xxx-xxx_xxx-1.4-1_WR3.0bg.armv6jel_vfp it shud still extract : 1.4-1 whenever "-"... (12 Replies)
Discussion started by: xerox
12 Replies

4. Shell Programming and Scripting

input of two numbers in the middle of the script

Hi, My script ask for the input of two numbers in the middle of it. I would like to know how to indicate this two numbers when I submit the script. thanks for any help, jalves (4 Replies)
Discussion started by: jalves
4 Replies

5. UNIX for Dummies Questions & Answers

constructing a file for printing

I have a text file, data.txt, which looks like :- head1 head2 head3 data1 1 data 1 2 data 1 3 data 2 1 data 2 2 data 2 3 data 3 1 data 3 2 data 3 3 etc etc I would like to print this file, using the lp -d command, with a heading line, as follows :- Report for whatever department as... (2 Replies)
Discussion started by: malts18
2 Replies

6. Shell Programming and Scripting

Suggestions on constructing a log file

Hi, I have a series of BASH shell scripts that run together. I would like it so that these scripts construct a log file as they run. This log file would ideally be a text file that contains exactly (including blank lines) what is output to the terminal. What is the best way to accomplish... (3 Replies)
Discussion started by: msb65
3 Replies

7. UNIX for Dummies Questions & Answers

Negative Numbers for input parameters.

Hello, I have a command that I need to supply a negative number as a parameter; how do I do this? I have tried giving it with double quotes, "", but no avail. Thanks, Gussi (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

8. Shell Programming and Scripting

How to remove all lines with something other than numbers

Hi, How would I get rid of lines having something else than numbers (such as tabs,white space, special characters, empty line, letters). So I have big file with numers as follows: 12345678901 23456789012 32343678901 42345638901 52345678901 and I sometimes the file might contain some... (2 Replies)
Discussion started by: Juha
2 Replies

9. Shell Programming and Scripting

Accept user input - only numbers

I have a situation where I want the user to enter only numbers in response to a READ command. I have some validation to restrict the number to be between 1 and 12, but if the user type in some characters the script echoes some error message and goes to the next command. Below is a snippet of the... (1 Reply)
Discussion started by: pvar
1 Replies

10. Shell Programming and Scripting

Is there any way to makesure that the input from the user is all numbers?

Is there any way to makesure that the input from the user is all numbers? thankz (5 Replies)
Discussion started by: XXXXXXXXXX
5 Replies
Login or Register to Ask a Question