1

I have thousands of xyz (latitude,longitude,elevation) text files that I want to separate by latitude or longitude. How and what commands could I use to create an "if latitude(column1) is greater than -1.00, than move to this directory"? for all files in my original directory.

I have been close with a couple different commands using grep or awk but not working exactly how I would like.

example list of files

2004_2006-361383_Morecambe_Bay_Heysham_Channel_s.xyz
2004_2006-361385_River_Mersey_Langton_Dock_Entrance_s.xyz
2004_2006-361399_Thames_Estuary_Gore_Channel_s.xyz

here is a sample of the first 10 lines of a file, many of these files have millions and millions of lines

-002.9584650 54.0087979 -5.3
-002.9416586 54.0326371 -1.3
-002.9307806 54.0323594 -8.5
-002.9644657 53.9985145 0.8
-002.9680185 54.0019534 -10
-002.9524820 54.0183868 -5
-002.9439942 54.0179227 -4.2
-002.9569578 54.0183595 -5.4
-002.9372192 54.0224494 -3.2
-002.9535454 54.0178188 -4.3
  • can you edit your post with file names, or file content ? – Archemar Apr 5 '16 at 15:07
  • you say if any column is greater than -1, move the (file?) - will a whole file be moved, or will different lines in a single file qualify for more than one "move" ? – Jeff Schaller Apr 5 '16 at 15:17
  • Yes, sorry i didn't specify. I would like if any value in column 1 is above or below the number I want, than move. – lbeazy Apr 5 '16 at 15:19
0

If file have no funny name (that is space)

global sort

awk 'FNR==1 { printf "mv %s ../dir%d\n",FILENAME,$1 ; next ; }' * | bash

north/south sort

awk 'FNR==1 { printf "mv %s ../%s\n",FILENAME,$1<0?"south":"north" ; next ; }' * | bash

where

  • FNR == 1 operate on first line of file
  • printf and %d will resolve to int part of column 1
  • replace | bash by | head -10 to check it is OK
  • next will skip remaining line an go to next file.
  • $1<0?"south":"north" will select either south or north

I supposed you want to move the whole file, and that all latitude are either above or below 0.

  • when I used this, it dissolves my files and just creates new files merging them together. Essentially, I would like to keep original file intact, just move them to a new directory based on if/than search criteria that I choose. – lbeazy Apr 5 '16 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.