Extracting values after the maximum value in a txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting values after the maximum value in a txt file
# 8  
Old 10-23-2018
I did not get the chopped-off version matrix. I wrote just to show in a basic way to make it simpler.


First value will be the maximum value in new txt file "0.4238688" and follows the string. Finally i try to 4*5 matrix again including 20 string like that;

Code:
0.4238688      0.4232734      0.4205554      0.4157534      0.4089370 
0.4002056      0.3896858      0.3775293      0.3639085      0.0000000            
0.0000000      0.0000000      0.0000000      0.0000000      0.0000000            
0.0000000      0.0000000      0.0000000      0.0000000      0.0000000


Thank you

Last edited by vgersh99; 10-23-2018 at 05:22 PM.. Reason: please start using code tags!
# 9  
Old 10-23-2018
Well, I don't get it.
Have you tried what's been posted in post #2 on this thread?
# 10  
Old 10-23-2018
Would this come close (stealing shamelessly from vgersh99)?
Code:
awk -vMX=$(tr -s ' ' '\n' < file | sort -nr | head -1) '{for (i=1; i<=NF; i++) {if ($i == MX) RC = 1; if (RC) {print $i; CNT++}}}END {for (i=CNT; i<20; i++) print "0.00"}' file | paste -d" " - - - - -
0.4238688 0.4232734 0.4205554 0.4157534 0.4089370
0.4002056 0.3896858 0.3775293 0.3639085 0.00
0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00

BTW, if you see you're losing people, it might make sense to rephrase, from another point of view.

Last edited by RudiC; 10-23-2018 at 05:48 PM.. Reason: Corrected from 5x5 matrix to 4x5, 25 to 20 max iterations.
This User Gave Thanks to RudiC For This Post:
# 11  
Old 10-23-2018
Ah, good guess RudiC - I didn't notice the pattern!
# 12  
Old 10-23-2018
Thank you so much RudiC

It worked. However i have some troubling about sorting (e.g. decimal problem) because i have some values like "3.652067e-08" and because of that sorted numerically wrong.


BTW, I tried to rephrase but i think i failed Smilie
# 13  
Old 10-23-2018
"After that" is a term that is highly dependent on the point of view, esp. in two or more dimensions. Is my observation correct that values increase by increasing column, then row, until reaching the max, then decrease again?


sort can cope with numbers in scientific notation if run with the -g, --general-numeric-sort option (in lieu of the -n) as it then will "compare according to general numerical value".
# 14  
Old 10-23-2018
Quote:
Originally Posted by RudiC
"After that" is a term that is highly dependent on the point of view, esp. in two or more dimensions. Is my observation correct that values increase by increasing column, then row, until reaching the max, then decrease again?


sort can cope with numbers in scientific notation if run with the -g, --general-numeric-sort option (in lieu of the -n) as it then will "compare according to general numerical value".


Yes you are so right. It worked now Smilie Thank you so much for also English lesson for different point of view i will keep it always in my mind.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To extract values after the maximum value in a txt file

Hello, I'm new to scripting and I need to write a bash script. Here is example of file on which I'm working: 0.3092381 0.3262799 0.3425480 0.3578379 0.3719490 0.3846908 0.3958855 0.4053738 0.4130160 0.4186991 0.4223357 ... (1 Reply)
Discussion started by: jeo_fb
1 Replies

2. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

3. Shell Programming and Scripting

Extracting files having maximum timestamp

Hi , I'm using Ksh 88 I've the following files in a directory with YearMonthDate (Ex:20130601) YDT:FILE1:20130601 YDT:FILE1:20130615 YDT:FILE2:20130601 YDT:FILE2:20130615 YDT:FILE3:20130601 YDT:FILE3:20130615 And i need the files having maximum timestamp , Means i need to display ... (8 Replies)
Discussion started by: smile689
8 Replies

4. Shell Programming and Scripting

AWK, Perl or Shell? Unique strings and their maximum values from 3 column data file

I have a file containing data like so: 2012-01-02 GREEN 4 2012-01-02 GREEN 6 2012-01-02 GREEN 7 2012-01-02 BLUE 4 2012-01-02 BLUE 3 2012-01-02 GREEN 4 2012-01-02 RED 4 2012-01-02 RED 8 2012-01-02 GREEN 4 2012-01-02 YELLOW 5 2012-01-02 YELLOW 2 I can't always predict what the... (4 Replies)
Discussion started by: rich@ardz
4 Replies

5. UNIX for Dummies Questions & Answers

extracting values from file using perl

I would like to read value after $ symbol from a file. For eg a file will be having the following lines. 5,$0,-32768p,32767p,$400014f8,1,, 5,$0,0,0,$400008ce,1,, 5,$0,0,0,$400008d0,1,, i would like to read 400014f8 then 400014f8 and similar all the value after $ symbol.Can any one help... (1 Reply)
Discussion started by: jagadeeshrr
1 Replies

6. Shell Programming and Scripting

extracting values from configuration file

Dear All, i am new to shell scripting, I am working on embedded system based on linux.I am supposed to the read the configuration file and edit another file. presently I would like to read from the configuration file.It would be having values file one below. There is chance of entering... (6 Replies)
Discussion started by: Ratheendran
6 Replies

7. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies

8. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies

9. Shell Programming and Scripting

Help needed in extracting text present between two headers in .txt file

Hi All, Please help me out in fllowing problem. I have text file which contains the data in following format. Contents of file.txt are setregid02 Test that setregid() fails and sets the proper errno values when a non-root user attemps to change the real or effective... (2 Replies)
Discussion started by: varshit
2 Replies

10. Shell Programming and Scripting

Extracting records with unique fields from a fixed width txt file

Greetings, I would like to extract records from a fixed width text file that have unique field elements. Data is structured like this: John A Smith NY Mary C Jones WA Adam J Clark PA Mary Jones WA Fieldname / start-end position Firstname 1-10... (8 Replies)
Discussion started by: sitney
8 Replies
Login or Register to Ask a Question