Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of files which contain an ascii header with a time stamp WITHIN the file, followed by a large chunck of binary data. I would like to list the files sorted by this time stamp, at the command line (bash, etc).

The file headers look similar to the following:

encoding: raw
endian: big
dimension: 4
sizes: 128 128 1 4
date_time: 06.02.12.18:59
user_name: Operator1
dwell_time: 4.000

....binary data....

I would like to sort based on the "date_time" time stamp, which uses the format dd.mm.yy.hh:mm

The sort --key option looks promising but all my attempts have failed. Any help is much appreciated. Thanks.

share|improve this question

1 Answer 1

$ grep ^date_time *.dat | sort -t: -k3
t8b.dat:date_time: 06.02.11.17:55
t8a.dat:date_time: 06.02.12.18:59

or to just output filenames

$ grep ^date_time *.dat | sort -t: -k3 | cut -d: -f1
t8b.dat
t8a.dat

Where the data files are

$ head *dat
==> t8a.dat <==
a
b
c
date_time: 06.02.12.18:59
d
e
f

==> t8b.dat <==
p
q
r
date_time: 06.02.11.17:55
x
y
z

You can use grep's -m 1 option to stop it searching through the subsequent (binary) data.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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