I have a normal…
for file in *
do
#do something here
done
…Code.
The problem is that I want to sort the row of the files by a custom date, the date is defined in the second line of the files.
I got to problems here:
1.How do I find out what’s in the second line of these multiple files before I actually run
for file in * do
2.How do I sort the loop by this custom string then?
This doesn’t work but maybe it will help you understanding my problem:
for file in *
do
customdate="$(sed -n 2p $file)"
done
for file in * sort by $customdate
do
#do something here
done
I think you need two loops. The first list reads that date out of the files and builds an index. and the second loop goes through that index. You can use a delimiter to split the index out again to get the filename out of the index again.