How to copy or cut specific rows from appended file with some conditions

Hi I have one file which is containing about 5000 rows and 20 columns

I will just explain about my requirement here briefly with sample file, I have attached also, please help....me..

1    28.25    36.42
5    28.26    36.42
10    28.23    36.43
15    28.22    36.43
20    28.2    36.42
25    28.19    36.43
0    28.25    36.42
1    28.26    36.42
5    28.23    36.43
10    28.22    36.43
15    28.2    36.42
20    28.19    36.43
25    28.25    36.42
3    28.26    36.42
5    28.23    36.43
10    28.22    36.43
15    28.2    36.42
20    28.19    36.43

consider 1st column only

here 1st station profile is 5 to 25, script has copy or cut 5 rows in a file, and to paste it in new file...

2nd profile starts from 0 to 25 script has copy or cut 7 rows in a file, and to paste it in another new file...

3rd profile starts from 3 to 20 script has copy or cut 5 rows in a file, and to paste it in another new file... till the end of file

Try:

awk 'NR==1 || $1<p{close(f); f="newfile_" ++n}{print>f; p=$1}' infile
1 Like

Given the simple assumption that a marker should be a smaller value in the first column than in the line previus for creation of a new file the following should do in bash:

rm file.*; export nf=0;lpiv=10000; while read l; do  piv=$(echo $l | cut -d" " -f1); if test "$piv" -lt $lpiv; then ((nf++)); echo "$l" >> file.$nf ; echo $piv;else echo "$l" >> file.$nf; fi ; lpiv=$piv  ; done < Input.txt 

sigh: humble & slow

And unreadable. Do all of your scripts looks like that? Is your Enter key broken?

1 Like

I don't understand what a station profile is nor how a shell script is supposed to figure out what lines to ignore and what lines to copy into the new files.

Scrutinizer's awk script makes a perfectly reasonable assumption that you want to take each grouping of lines with increasing values in the 1st column into separate files. But, you say that the 1st new file should contain 5 rows while Scrutinizer's awk script will make newfile_1 contain 6 rows. You say that the 2nd new file should contain 6 rows, but Scrutinizer's awk script will make newfile_2 contain 7 rows. The only match is that you say the the 3rd new file should contain 5 rows and Scrutinizer's script will print 5 rows into newfile_3.

Please explain what logic should be used to produce the output you want AND please post the output that you believe should appear in those three files (in CODE tags).

Sorry though, just a bad habit of one-lining...

Sorry, there were some mistakes, Scrutinizer scripts is absolutely fine..