Visit Our UNIX and Linux User Community


Find the minimum number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the minimum number
# 1  
Old 09-16-2009
Find the minimum number

Input
Code:
10     8     20     8     10     9     20     9
10     12     20     19     10     10     20     40

Output1
Code:
10     8     2     20     8     12     10     9     1     20     9     11
10     12     -2     20     19     1     10     10     0     20     40     -20

Output2
Code:
10     9     1
20     40     -20

First I would like to take the difference of the 1st column and second column and print as 3rd column (10-8=2) and same follows to the 3&4, 5&6, 7&8 columns.
I assume this is the code that can print the output1
Code:
awk '{print $1,$2,$1-$2,$3,$4,$3-$4,$5,$6,$5-$6,$7,$8,$7-$8}' Input

Second I would like to compare the values (the new columns like 3rd(the value of $1-$2) and 6th($3-$4),9($5-$6)th and 12th ($7-$8)) of the 4 fields (2 \t 12 \t 1 \t 11) and print the the set with minimum difference

For example the first minimum value in 1st row is 1 (i.e.10-9). So it has to be in output2 and second minimum value in 2nd row is -20 (20-40). So it has to be in output2.

I think I explained little bit broadly to understand easily.

Thanx

---------- Post updated at 10:34 PM ---------- Previous update was at 07:27 PM ----------

I solved it Thanx
This is for output1
Code:
awk '{print $1,$2,$1-$2,$3,$4,$3-$4,$5,$6,$5-$6,$7,$8,$7-$8}' Input.txt

This is for output2
Code:
awk '{if($3<$6 && $3<$9 && $3<$12) {print$1,$2,$3} if($6<$3 && $6<$9 && $6<$1
2) {print $4,$5,$6} if($9<$3 && $9<$6 && $9<$12) {print $7,$8,$9} if {print $12<$3 && $12<$6 && $12<$9) {print
10,$11,$12}}' Output1.txt


Last edited by repinementer; 09-16-2009 at 05:44 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #88
Difficulty: Easy
PowerShell makes use of pipes.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

2. UNIX for Dummies Questions & Answers

Absolute minimum value of a number using awk

Hi, I have got a file in the following format: 4300 23695 4305 03591 4400 125368 I need to sort this file to find the minimum absolute value of the numbers starting from 6th pos, so the expected output is:- 4300 23569 4305 01359 4400 123568 I tried to cut out the file from 6th... (7 Replies)
Discussion started by: roy121
7 Replies

3. Shell Programming and Scripting

Python: find the minimum in all rows

I am using Biopython to process an alignment in fasta format. I need to slice the sequences where there is the first stop codon. So I divided my alignment in codons and found the stop. I then found the first codon position using enumerate(). But I found the minimum for each row. However I need to... (0 Replies)
Discussion started by: Homa
0 Replies

4. Shell Programming and Scripting

How to find a minimum value of a row?

input 1 2 3 4 5 2 8 2 1 1 1 4 2 1 5 4 4 4 2 1 3 2 2 6 7 4 5 4 5 5 5 4 3 3 5 I woud like to print a min of each row such that my output would look like 1 1 1 2 3 (5 Replies)
Discussion started by: johnkim0806
5 Replies

5. Shell Programming and Scripting

In a row, replace negative sign and find minimum value among four columns

Hi Friends, I have an input file like this chr1 100 200 1 2 3 4 chr1 150 200 4 5 6 7 chr2 300 400 9 6 7 1 chr2 300 410 -10 21 -11 13 chr3 700 900 -21 -22 130 165 Now, my output file is chr1 100 200 1 chr1 150 200 4 chr2 300 400 1 chr2 300 410 10 chr3 700 900 21 Remove... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

6. Shell Programming and Scripting

Find minimum value different from zero

Hello, I have this file file1.csv Element1;23-10-2012;1,450;1,564;1,428 Element2;23-10-2012;1,448;1,565;1,427 Element3;23-10-2012;1,453;1,570;1,424 Element4;23-10-2012;1,428;1,542;1,405 Element5;23-10-2012;1,461;;1,453 Element6;23-10-2012;1,438;1,555;1,417... (6 Replies)
Discussion started by: saba01
6 Replies

7. Shell Programming and Scripting

grep - match files containing minimum number of pattern matches

I want to search a bunch of files and list only those containing a minimum number of pattern matches. So if I want to identify files containing 3 (or more) instances of the pattern "said:" and I have file1 that contains the lines: He said: She said: and file2 that contains the lines: He... (3 Replies)
Discussion started by: stumpyuk
3 Replies

8. Shell Programming and Scripting

Find the minimum value

Hi there I have generated a column containing 100.000 values. Sample: 94.971 101.468 73.120 100.601 102.329 I need to find the minimum value in this file and I must know which row it is in (no sorting). I hope you can help! Thanks! (16 Replies)
Discussion started by: cno
16 Replies

9. Linux

What is the minimum number of partitions you need to install Linux?

I think its 3. Just to know if I am correct. / /boot swap :confused: (2 Replies)
Discussion started by: nitin09
2 Replies

10. Shell Programming and Scripting

minimum number of unique key

input a 1 a 2 a -1 b 1 b 2 b 3 output a -1 b 1 Thanx ---------- Post updated at 09:42 PM ---------- Previous update was at 09:10 PM ---------- Ok I managed it (7 Replies)
Discussion started by: repinementer
7 Replies

Featured Tech Videos