Skip to content

Instantly share code, notes, and snippets.

@giumas
Created March 9, 2018 03:52
Show Gist options
  • Save giumas/d34de0331e38d3f037cbc9ce130c6b76 to your computer and use it in GitHub Desktop.
Save giumas/d34de0331e38d3f037cbc9ce130c6b76 to your computer and use it in GitHub Desktop.
Remove rows with accepted beams from a Caris text file with "Lat (DD) Long (DD) Year Day Time Profile Beam Status"
import os
def remove_accepted_beams(file_folder):
for path, subdirs, files in os.walk(file_folder):
for name in files:
file_path = os.path.join(path, name)
tmp_path = os.path.join(path, name + ".tmp")
print("path: %s" % file_path)
with open(file_path, 'r') as fid:
fod = open(tmp_path, "w")
lines = fid.readlines()
for idx, line in enumerate(lines):
if idx == 0:
fod.write(line)
continue
tokens = line.split()
if len(tokens) < 8:
print("issue with line %d" % idx)
break
if tokens[7][0] == "A":
continue
fod.write(line)
fod.close()
os.remove(file_path)
os.rename(tmp_path, file_path)
file_folder = "C:\\Users\\gmasetti\\Dropbox\\ifremer\\renamed\\ascii"
remove_accepted_beams(file_folder=file_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment