The way I'm reading this question is that you'd like to create the CSV formatted output given a list of files. For another interpretation, see the end of this answer.
Here's a shell script that will do this. It uses the Linux version of stat
to get the timestamp of last modification.
#!/bin/sh
echo "PATHNAME,TIMESTAMP"
stat -c '"%n",%y' "$@"
After outputting a header, this script simply calls stat
with the pathnames mentioned on the command line to get the timestamp of last modification (see the manual for stat
on your system to figure out how to change this). It prints the pathname (quoted) and the timestamp.
You would use this as
sh script.sh PATTERN >outputfile
For example:
$ sh script.sh *.log* *.tar >file.cvs
$ cat file.cvs
PATHNAME,TIMESTAMP
"dsmerror.log",2018-07-17 13:00:02.911711652 +0200
"dsminstr.log",2018-07-17 13:00:04.079726608 +0200
"dsminstr.log.bak",2018-05-13 18:00:03.231791181 +0200
"dsminstr.log.lock",2018-07-17 13:00:04.079726608 +0200
"archive_20170823-old.tar",2017-08-22 16:44:23.037803149 +0200
"archive_20170823.tar",2017-08-23 09:35:28.956158119 +0200
"archive_20180409.tar",2018-04-09 09:47:29.472374428 +0200
"archive-chr22.tar",2018-06-19 14:50:45.896447161 +0200
"gene_cache.tar",2018-04-25 09:44:15.518486626 +0200
Since the script is so short, its commands may be written directly on the command line. The equivalent command line for the example above would be
$ { echo "PATHNAME.TIMESTAMP"; stat -c '"%n",%y' *.log* *.tar; } >file.cvs
Now when we have this file, we may want to format it nicely for reporting purposes:
$ column -s, -t file.csv
PATHNAME TIMESTAMP
"dsmerror.log" 2018-07-17 13:00:02.911711652 +0200
"dsminstr.log" 2018-07-17 13:00:04.079726608 +0200
"dsminstr.log.bak" 2018-05-13 18:00:03.231791181 +0200
"dsminstr.log.lock" 2018-07-17 13:00:04.079726608 +0200
"archive_20170823-old.tar" 2017-08-22 16:44:23.037803149 +0200
"archive_20170823.tar" 2017-08-23 09:35:28.956158119 +0200
"archive_20180409.tar" 2018-04-09 09:47:29.472374428 +0200
"archive-chr22.tar" 2018-06-19 14:50:45.896447161 +0200
"gene_cache.tar" 2018-04-25 09:44:15.518486626 +0200
This works unless any of the pathnames contains a comma.
To properly format this with a CSV parser, which would also cope with pathnames containing commas:
$ csvlook file.csv
| PATHNAME | TIMESTAMP |
| ------------------------ | ----------------------------------- |
| dsmerror.log | 2018-07-17 13:00:02.911711652 +0200 |
| dsminstr.log | 2018-07-17 13:00:04.079726608 +0200 |
| dsminstr.log.bak | 2018-05-13 18:00:03.231791181 +0200 |
| dsminstr.log.lock | 2018-07-17 13:00:04.079726608 +0200 |
| archive_20170823-old.tar | 2017-08-22 16:44:23.037803149 +0200 |
| archive_20170823.tar | 2017-08-23 09:35:28.956158119 +0200 |
| archive_20180409.tar | 2018-04-09 09:47:29.472374428 +0200 |
| archive-chr22.tar | 2018-06-19 14:50:45.896447161 +0200 |
| gene_cache.tar | 2018-04-25 09:44:15.518486626 +0200 |
csvlook
is part of csvkit
, a Python toolkit for working with CSV files.
csv2tsv
converter.) It would help if you clarify what you want to do with the result. Thecolumn
command is used to pretty-print for reading, but is less useful for subsequent processing by other tools. – JonDeg Jul 07 '18 at 04:50