How do I standardise an entire column?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How do I standardise an entire column?
# 1  
Old 04-06-2010
How do I standardise an entire column?

I have a kind of a multi-step problem:
What I want to do is: To find the maximum value in the second column, divide the entire column with this value and multiply with a user defined variable (e.g. x=400). The result should be written to a new file.

I.e., find max value of column 2 and perform the operation:
"val. column 2"*x/max

Example file:

*KEYWORD
*INITIAL_TEMPERATURE_NODE
52000290 457.10728
52000291 457.60783
52000292 457.10728
52000300 442.74765
52000301 443.36406
. .
. .
. .

New file:
*KEYWORD
*INITIAL_TEMPERATURE_NODE
52000290 399,56246
52000291 400.00000
52000292 399,56246
. .
. .
. .

Any suggestions?
Thx a lot...
# 2  
Old 04-06-2010
Something like this?
Code:
awk 'NR==FNR{if(NR>2 && $2>m){m=$2};next}
FNR>2{$2=*400/m}1' file file

# 3  
Old 04-06-2010
I get nothing written to the new.file when i execute

awk 'NR==FNR{if(NR>2 && $2>m){m=$2};next}FNR>2{$2*400/m}1' ex.file new.file
# 4  
Old 04-06-2010
Quote:
Originally Posted by Medova
I get nothing written to the new.file when i execute

awk 'NR==FNR{if(NR>2 && $2>m){m=$2};next}FNR>2{$2*400/m}1' ex.file new.file
The command should be:

Code:
awk 'NR==FNR{if(NR>2 && $2>m){m=$2};next}
FNR>2{$2=*400/m}1' ex.file ex.file > newfile

# 5  
Old 04-06-2010
MySQL

Perfect... Works like a charm
Thx a lot

However, this is written for shell (?) - since I have to do some more manipulation, like the output digit format, so can you help with the syntax for an awk-script?

Last edited by Medova; 04-06-2010 at 09:11 AM..
# 6  
Old 04-07-2010
Medova, awk is not a shell, it is called by the shell. It is a programmable text filter or - if you prefer this definition - a programming language designed specifically for the processing of text files.

Regarding your problem: it would be better to post a clear, concise and complete description of what it is instead of starting with a part, then ask for the next part, etc..

Here is a link you might find useful:

How to ask questions the smart way

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

2. Shell Programming and Scripting

Copying a single value to the entire column

Hello everone, I have a text file as input, which lokks like for exemple: # # # 12 2 3 12 12 12 12 12 12 12 It has three column. My question is, i want to copy the value of 2nd column, 1st row to the entire 2nd column. similarly for the third column also. My result... (7 Replies)
Discussion started by: dinesh.n
7 Replies

3. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies

4. UNIX for Dummies Questions & Answers

Fill csv entire column with content from another text file

I have a csv that looks like this: ,yude-to-nap2,0,0,0,0,0 ,2twis-yude-to-nap2,0,0,0,0,0 ,2tiws-yude-to-nap2,0,0,0,0,0 ,2arcos-yude-to-nap2,0,0,0,0,0 and another file named m1 that has a single line of text as content: Feb 1 15:30:20 How can I fill the whole the empty column of the... (1 Reply)
Discussion started by: RobertoRivera
1 Replies

5. Shell Programming and Scripting

Delete an entire column from a tab delimited file

Hi, Can anyone please tell me about how we can delete an entire column from a tab delimited file? Mu input_file.txt looks like this: And I want the output as: I used the below code nawk -v d="1" 'BEGIN{FS=OFS="\t"}{$d=""}{print}' input_file.txtBut in the output, the first column is... (5 Replies)
Discussion started by: sampoorna
5 Replies

6. Shell Programming and Scripting

Print entire line based on value in a column

Friends, File1.txt abc|0|xyz 123|129|opq def|0|678 890|pqw|sdf How do I print the entire line where second column has value is 0? Expected Result: abc|0|xyz def|0|678 Thanks, Prashant ---------- Post updated at 02:14 PM ---------- Previous update was at 02:06 PM ---------- ... (1 Reply)
Discussion started by: ppat7046
1 Replies

7. Shell Programming and Scripting

edit entire column from a fixed-width file using awk or sed

Col1 Col2 Col3 Col4 12 Completed 08 0830 12 In Progress 09 0829 11 For F U 07 0828 Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
Discussion started by: tamahomekarasu
10 Replies

8. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

9. UNIX for Advanced & Expert Users

Updating entire column irrespective of any data in a file

Hi, I have a file A.txt (tab separated) as below: pavan chennai/tes/bangalore 100 sunil mangalore/abc/mumbai 230 kumar delhi/nba/andhra 310 I want to change only second column as below . Rest of columns as it is ;The ouput file is also tab... (4 Replies)
Discussion started by: kpavan2004
4 Replies

10. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies
Login or Register to Ask a Question