Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split one file into several parts 2

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

my files look like this:

19.989182 -82.379220
19.983025 -82.377908
19.976869 -82.376596
19.970714 -82.375284
19.964563 -82.373970
19.958413 -82.372655
19.952262 -82.371340
19.946107 -82.370026
19.939946 -82.368713
19.933776 -82.367402
19.927602 -82.366093
19.921424 -82.364784
19.915240 -82.363478
-19.909052 -82.362174
-19.902864 -82.360870
-19.896679 -82.359566
-19.890500 -82.358260
-19.884328 -82.356951
-19.878167 -82.355641
-19.872018 -82.354330
-19.865890 -82.353016
-19.859783 -82.351702
-19.853688 -82.350387
19.835438 -82.346444
19.829359 -82.345131
19.823279 -82.343817

now, i want to cut this file, when the difference between the values of $1 is greater than 2 and write the lines up to this cut into a seperate file. e.g.

file 1:
19.989182 -82.379220
19.983025 -82.377908
19.976869 -82.376596
19.970714 -82.375284
19.964563 -82.373970
19.958413 -82.372655
19.952262 -82.371340
19.946107 -82.370026
19.939946 -82.368713
19.933776 -82.367402
19.927602 -82.366093
19.921424 -82.364784
19.915240 -82.363478

file 2:
-19.909052 -82.362174
-19.902864 -82.360870
-19.896679 -82.359566
-19.890500 -82.358260
-19.884328 -82.356951
-19.878167 -82.355641
-19.872018 -82.354330
-19.865890 -82.353016
-19.859783 -82.351702
-19.853688 -82.350387

file 3:
19.835438 -82.346444
19.829359 -82.345131
19.823279 -82.343817

$1 is always in ascending or descending order.

i tried so far:

awk 'NR>1{x=$1-y1;printf"%10.6f\t%10.6f\n",$1, $2, x{y3=$3}' infile > output

but this only finds the differences. can anybody help me?

thanks



 
Something like this ?
awk '(x-$1)*((x>$1)+(-1*(x<$1)))>2{++f}{print>"file"f;x=$1}' infile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hi PHV

thanks for your answer, but this doesn't work. its bailing out. i've checked some files by hand and find out some maybe helpful things:

$1 is always ascending so, if a value in $1 in one line is higher than the value in the line before, write a new file

the maximum count of resulting files is 8

cheers,tini
 
hi all....

i am still interested in a solution of my problem.

phv: i looked at our solution and i do not understand the command, so i can not find any error. sorry.... :-(

 
PHV's solution works for me (to exactly your specification)

(awk on AIX 53)

What OS are you on?




HTH,

p5wizard
 
hi p5wizard,

your question about my system gave me the solution!
normally, i use an unix server and now i tried cygwin on windows and it works very well!

i think, its a problem on the server, because in the last weeks, no awk-command works on the unix system. i will call our system administrator!

so...p5wizard, thanks a lot and

phv.....also thanks a lot!!!!!!!

cheers, tini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top