|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.. Code:
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 Last edited by nex_asp; 12-08-2012 at 02:49 AM.. Reason: modify.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try: Code:
awk 'NR==1 || $1<p{close(f); f="newfile_" ++n}{print>f; p=$1}' infileLast edited by Scrutinizer; 12-04-2012 at 05:59 PM.. Reason: Added file close |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
nex_asp (12-08-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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: Code:
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 |
|
#4
|
||||
|
||||
|
Quote:
|
| The Following User Says Thank You to Scott For This Useful Post: | ||
joeyg (12-04-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
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). |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Sorry though, just a bad habit of one-lining...
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Sorry, there were some mistakes, Scrutinizer scripts is absolutely fine..
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with deleting specific rows from a text file | evelibertine | UNIX for Dummies Questions & Answers | 1 | 06-28-2011 02:03 PM |
| How to copy specific file.txt in specific folder? | annetote | Shell Programming and Scripting | 17 | 06-02-2010 12:50 PM |
| Deleting specific rows in large files having rows greater than 100000 | manish2009 | Shell Programming and Scripting | 9 | 12-11-2009 12:17 PM |
| Copy Limited rows from one file to another | ravi214u | Shell Programming and Scripting | 3 | 12-17-2008 05:15 AM |
| How to copy set of files with date appended to their name | sish78 | UNIX for Dummies Questions & Answers | 7 | 07-07-2008 05:21 PM |
|
|