Skip to content

Instantly share code, notes, and snippets.

@ssp
Last active November 28, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssp/db6d14d485720a561f5b3eaf824f28d2 to your computer and use it in GitHub Desktop.
Save ssp/db6d14d485720a561f5b3eaf824f28d2 to your computer and use it in GitHub Desktop.
# alle Dateien, deren Name auf _B endet …
find . -name "*_B" -print0 | xargs -0 ./reduce.py > processed.csv
# erster Versuch mit Pipes
cat 20181011_06-04-51_B \
| awk 'NR == 1 || NR == 2 || NR % 100 == 0' \
| sed -e 's/ \+/ /g' \
| cut -d ' ' -f 1-10 \
> 20181011_06-04-51_B-reduced
#!/usr/bin/env python
import re
import datetime
import time
import sys
dateFormat = '%Y%m%d_%H-%M-%S'
def processFile(path):
dateString = re.sub('.*(\d\d\d\d\d\d\d\d_\d\d-\d\d-\d\d).*' , '\\1', path)
startTime = datetime.datetime.strptime(dateString, dateFormat)
startTimestamp = time.mktime(startTime.timetuple())
with open(path, "r") as inputFile:
linenumber = 0
for line in inputFile:
linenumber += 1
if linenumber % 100 == 0:
singlespaces = re.sub('\n', '', re.sub(r' +', ' ', line))
columns = singlespaces.split(' ')
currentTimestamp = float(startTimestamp) + float(columns[0])
result = [str(int(currentTimestamp))] + columns
print(' '.join(result))
fileNames = sys.argv[1:]
for fileName in fileNames:
processFile(fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment