AWK processing -numbers to another column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK processing -numbers to another column
# 1  
Old 10-21-2009
AWK processing -numbers to another column

Hi Guys,

I'm trying to clean up my home logger file and can't seem to work this out.

Here is my data:

Code:
10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9
10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4
10-19-2009 08:42 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4
10-19-2009 08:43 00.1 00.0 00.6 00.8 24.5 0.0 147.3 196.4 -24.5 171.9
10-19-2009 08:44 00.4 00.0 00.6 00.9 98.2 0.0 147.3 220.9 24.5 245.5

What I'm trying to do is that the $11 column needs to replaced with 0.0 if it is negative. Then the negative number needs to go in a new column $13 as a positive. Otherwise if nothing needs to be changed, like the second row, 0.0 should be added to $13.

so for example the top two line should end up looking like this after processing:

Code:
10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 0.0 220.9 49.1
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 0.0

Thanks for any help!

Bj
# 2  
Old 10-22-2009
Hi BeJay, Is this what you mean?
Code:
awk '{if ($11<0) {$13=-$11; $11="0.0"} else $13="0.0"} 1' infile

output:
Code:
10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 0.0 220.9 49.1
10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 0.0
10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4 0.0
10-19-2009 08:42 00.1 00.0 00.7 00.8 24.5 0.0 171.9 196.4 0.0 196.4 0.0
10-19-2009 08:43 00.1 00.0 00.6 00.8 24.5 0.0 147.3 196.4 0.0 171.9 24.5
10-19-2009 08:44 00.4 00.0 00.6 00.9 98.2 0.0 147.3 220.9 24.5 245.5 0.0


Last edited by Scrutinizer; 10-22-2009 at 01:57 AM..
# 3  
Old 10-22-2009
That is perfect Scrutinizer Smilie

I didn't know you could use if/then statements in AWK, so that makes it much easier to understand. I've been bashing my head for quite a while Smilie

Thanks again!

Bj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to replace numbers in a file with a column from another file

Hello, I am trying to make a awk code that will take 2 files, a txt file like this : 1 1 88 c(1:38, 42, 102) 2 2 128 c(39:41, 43:101, 103:105, 153, 155:189, 292, 344:369) 3 3 84 c(190:249, 603, 606:607, 609:629) 4 4 12 ... (8 Replies)
Discussion started by: nastaziales
8 Replies

2. Shell Programming and Scripting

Help with awk script to get missing numbers in column 1

Hello to all, I have show below a file separated by commas. In first column has numbers where the last number is 13. 1,4 2,6 3,7 5,2 6,5 7,5 8,65 9,10 11,78 13,2 What I want to know is which numbers are missing from 1 to 13 (in this case 13 is last number in column 1). My real... (17 Replies)
Discussion started by: Ophiuchus
17 Replies

3. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

4. Shell Programming and Scripting

AWK "make a new column that include increasing numbers"

please help!!!!!! I have a file .txt that has only one column like that: 34.1 35.5 35.6 45.6 ... Now, i want to add a column in the left in which the values of this column increase by 0.4 , for example: 0.0 34.1 0.4 35.5 0.8 35.6 1.2 45.6 How can i do with awk instructions??? ... (2 Replies)
Discussion started by: tienete
2 Replies

5. Shell Programming and Scripting

Help with File processing - Extracting the column

I have a line from table space report: 5 135_TT ms Normal 1774336.0 1774208.0 761152.0 1013056.0 57.1% Now I have to get 1013056.0 as o/p. For this I tried cut -f32 -d" " previously it worked now it is showing empty space. Suggest me the best code for this which... (1 Reply)
Discussion started by: karumudi7
1 Replies

6. Programming

AWK processing of a three-column file

I have a 3-column data file, for which I wish to print certain parts of $3 PHI PSI A(x) -177.5 -177.5 1.0625 -177.5 -172.5 0.55 -177.5 -167.5 0.0478125 -177.5 -162.5 0 -177.5 -157.5 0.284375 -177.5 -152.5 0.187188 -177.5 -147.5 0.236875 -177.5 -142.5 0.383438 -177.5 ... (3 Replies)
Discussion started by: chrisjorg
3 Replies

7. Shell Programming and Scripting

Processing text variables that have numbers in CShell

Hello, I have a case where I need to process an environment variable text value in CShell to calculate the product of 2 numbers stated in the variable string having the format "<first_number>Letter x<second_number>". Ex: $VAR = "24x20" I need to set $VAR_PRODUCT = "Product of 20 and 24"... (3 Replies)
Discussion started by: mohy
3 Replies

8. Shell Programming and Scripting

trying to make an AWK code for ordering numbers in a column from least to highest

Hi all, I have a large column of numbers like 5.6789 2.4578 9.4678 13.5673 1.6589 ..... I am trying to make an awk code so that awk can easily go through the column and arrange the numbers from least to highest like 1.6589 2.4578 5.6789 ....... can anybody suggest, how can I do... (5 Replies)
Discussion started by: ananyob
5 Replies

9. UNIX for Dummies Questions & Answers

Increasing numbers in Column

I have UWIn version of Unix for Desktop. I have a file (Subtitle file of a movie) with the following format abc def ghi jkl mno pqr stuv uvw xyz The subtitles are delayed about a min or few seconds more. I want to increase it to be as shown below: abc def ghi jkl mno pqr stuv ... (4 Replies)
Discussion started by: bobbygsk
4 Replies

10. Shell Programming and Scripting

processing matrix column wise

I have a m X n matrix written out to file, say like this: 1,2,3,4,5,6 2,6,3,10,34,67 1,45,6,7,8,8 I want to calculate the column averages in the MINIMUM amount of code or processing possible. I would have liked to use my favorite tool, "AWK" but since it processes rowwise, getting the... (5 Replies)
Discussion started by: Abhishek Ghose
5 Replies
Login or Register to Ask a Question