append find command result to csv

jimleslie1977

New Member
Joined
Feb 25, 2020
Messages
14
Reaction score
1
Credits
87
Hi and thanks for the help in advance

im using this command to output the latest time stamp of modifed files in a directoy and works well to screen

find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf "ajm293, %TY-%Tm-%Td , %TT\n , " | sort -nr | head -n 1
this gives output to console of:
, ajm293, 2020-05-14 , 14:54:38

i wanted to appendin this to a central csv file using this line:
find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf >> /nas/quota/slot_2/root_vdm_2/homeshare/home/jltest/output.csv "ajm293_%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1

but this is what i get instead of the single line as above:
ajm293, 2020-05-11 , 10:27:02
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2019-06-06 , 08:00:51
, ajm293, 2019-04-17 , 13:13:56
, ajm293, 2019-06-06 , 08:00:51
, ajm293, 2019-01-17 , 09:13:50
, ajm293, 2019-01-17 , 09:13:50
, ajm293, 2020-03-31 , 16:13:10
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2019-01-17 , 09:13:50
, ajm293, 2019-01-17 , 09:13:50
, ajm293, 2019-12-09 , 14:27:44
, ajm293, 2019-12-09 , 14:27:44
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2019-01-17 , 09:13:51
, ajm293, 2019-01-17 , 09:13:51
, ajm293, 2020-04-16 , 07:47:28
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2020-02-18 , 09:40:32
, ajm293, 2019-06-11 , 12:27:14
, ajm293, 2019-01-17 , 09:13:51
, ajm293, 2020-04-16 , 07:45:49
, ajm293, 2020-02-18 , 09:41:45
, ajm293, 2019-03-05 , 08:32:51
, ajm293, 2020-02-18 , 09:39:21
, ajm293, 2019-01-18 , 13:35:52
, ajm293, 2019-01-18 , 13:35:53
, ajm293, 2018-08-22 , 01:00:00
, ajm293, 2019-01-14 , 13:47:08
, ajm293, 2019-01-14 , 13:42:18
, ajm293, 2020-02-28 , 14:01:27
, ajm293, 2019-01-15 , 12:56:28
, ajm293, 2019-01-18 , 13:30:57
, ajm293, 2019-01-18 , 13:35:53
, ajm293, 2019-01-08 , 14:11:27
, ajm293, 2019-01-08 , 14:11:27
, ajm293, 2019-01-18 , 13:35:53
, ajm293, 2019-01-08 , 14:11:27
, ajm293, 2019-01-18 , 13:35:54
, ajm293, 2019-01-18 , 13:35:53
, ajm293, 2019-01-14 , 08:32:56
, ajm293, 2019-01-14 , 08:32:56
, ajm293, 2019-01-04 , 15:22:50
, ajm293, 2019-01-21 , 13:35:40
, ajm293, 2019-01-21 , 13:35:40
, ajm293, 2019-04-03 , 17:07:23
, ajm293, 2019-01-22 , 14:24:26
, ajm293, 2019-01-22 , 14:24:26
, ajm293, 2019-01-22 , 14:24:27
, ajm293, 2019-01-22 , 14:24:27
, ajm293, 2019-01-22 , 14:24:27
, ajm293, 2019-01-22 , 14:24:27
, ajm293, 2019-01-22 , 14:24:33
, ajm293, 2019-03-05 , 08:33:20
, ajm293, 2019-03-05 , 08:33:20
, ajm293, 2019-03-05 , 08:33:20
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-03-05 , 08:33:20
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-06-27 , 12:26:42
, ajm293, 2019-03-11 , 14:04:34
, ajm293, 2019-04-03 , 08:09:52
, ajm293, 2019-01-22 , 14:24:27
, ajm293, 2019-09-03 , 07:44:09
, ajm293, 2019-02-21 , 15:33:11
, ajm293, 2019-09-03 , 07:43:56
, ajm293, 2019-03-05 , 08:33:19
, ajm293, 2019-03-05 , 08:33:19
, ajm293, 2019-03-05 , 08:33:19
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-03-05 , 08:33:20
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-06-27 , 12:26:41
, ajm293, 2019-03-05 , 08:33:19
, ajm293, 2019-03-21 , 12:44:47
, ajm293, 2014-01-21 , 19:07:28
, ajm293, 2014-01-21 , 19:07:28
, ajm293, 2014-01-21 , 19:07:28
, ajm293, 2014-01-21 , 19:07:28
, ajm293, 2019-03-28 , 15:41:24
, ajm293, 2019-07-19 , 15:48:59
, ajm293, 2019-04-17 , 15:23:39
, ajm293, 2019-04-17 , 15:21:33
, ajm293, 2019-04-17 , 15:23:25
, ajm293, 2019-04-17 , 15:21:46
, ajm293, 2019-04-17 , 15:23:31
, ajm293, 2019-07-26 , 11:27:54
, ajm293, 2019-08-15 , 17:09:03
, ajm293, 2019-08-15 , 16:32:55
, ajm293, 2019-08-15 , 16:32:55
, ajm293, 2019-08-15 , 16:59:49
, ajm293, 2019-08-15 , 16:33:54
, ajm293, 2019-08-15 , 16:34:15
, ajm293, 2019-08-15 , 16:56:09
, ajm293, 2019-08-15 , 16:56:27
, ajm293, 2019-08-15 , 17:00:13
, ajm293, 2019-08-15 , 17:08:43
, ajm293, 2019-08-15 , 17:09:03
, ajm293, 2020-04-02 , 13:20:28
, ajm293, 2020-04-02 , 13:20:29
, ajm293, 2019-12-10 , 13:25:07
, ajm293, 2019-12-10 , 13:25:06
, ajm293, 2019-12-10 , 13:25:06
, ajm293, 2019-12-12 , 07:04:00
, ajm293, 2019-12-01 , 09:54:14
, ajm293, 2019-12-01 , 09:54:50
, ajm293, 2019-12-01 , 09:55:15
, ajm293, 2019-12-01 , 09:55:52
, ajm293, 2019-12-01 , 09:56:16
, ajm293, 2019-12-01 , 09:56:57
, ajm293, 2019-12-01 , 10:04:07
, ajm293, 2019-12-01 , 10:04:35
, ajm293, 2019-12-01 , 10:05:08
, ajm293, 2019-12-01 , 09:59:01
, ajm293, 2019-12-01 , 09:59:20
, ajm293, 2019-12-05 , 07:15:40
, ajm293, 2019-12-01 , 09:59:56
, ajm293, 2019-12-01 , 11:05:20
, ajm293, 2019-12-05 , 07:14:58
, ajm293, 2019-12-01 , 10:00:39
, ajm293, 2019-12-01 , 10:01:37
, ajm293, 2019-12-01 , 10:02:06
, ajm293, 2019-12-01 , 11:09:43
, ajm293, 2019-12-01 , 11:10:05
, ajm293, 2019-12-01 , 11:10:28
, ajm293, 2019-12-01 , 11:11:07
, ajm293, 2019-12-01 , 10:06:36
, ajm293, 2019-12-05 , 07:16:47
, ajm293, 2019-12-05 , 07:40:33
, ajm293, 2019-12-05 , 07:41:07
, ajm293, 2019-12-05 , 07:41:39
, ajm293, 2019-12-10 , 13:54:03
, ajm293, 2019-12-10 , 13:55:54
, ajm293, 2019-12-10 , 13:56:38
, ajm293, 2019-12-10 , 14:00:26
, ajm293, 2019-12-10 , 14:50:44
, ajm293, 2019-12-10 , 14:51:29
, ajm293, 2019-12-10 , 14:51:57
, ajm293, 2019-12-10 , 14:52:56
, ajm293, 2019-12-11 , 07:26:30
, ajm293, 2019-12-10 , 14:53:31
, ajm293, 2019-12-10 , 14:57:02
, ajm293, 2019-12-10 , 14:57:31
, ajm293, 2019-12-10 , 14:59:16
, ajm293, 2019-12-11 , 14:15:56
, ajm293, 2019-12-11 , 14:16:57
, ajm293, 2019-12-10 , 11:35:59
, ajm293, 2019-06-20 , 07:40:13
, ajm293, 2020-05-11 , 10:29:23
, ajm293, 2020-05-11 , 10:41:12
, ajm293, 2020-05-11 , 10:27:03
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:27:56
, ajm293, 2020-05-11 , 10:27:57
, ajm293, 2020-05-11 , 10:27:06
, ajm293, 2020-05-11 , 10:27:57
, ajm293, 2020-05-11 , 10:27:11
, ajm293, 2020-05-11 , 10:27:12
, ajm293, 2020-05-11 , 10:27:24
, ajm293, 2020-05-11 , 10:27:24
, ajm293, 2020-05-11 , 10:27:16
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:27:29
, ajm293, 2020-05-11 , 10:27:29
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:29:04
, ajm293, 2020-05-11 , 10:27:44
, ajm293, 2020-05-11 , 10:28:32
, ajm293, 2020-05-11 , 10:28:37
, ajm293, 2020-05-11 , 10:28:35
, ajm293, 2020-05-11 , 10:28:34
, ajm293, 2020-05-11 , 10:28:34
, ajm293, 2020-05-11 , 10:28:35
, ajm293, 2020-05-11 , 10:27:41
, ajm293, 2020-05-11 , 10:27:45
, ajm293, 2020-05-11 , 10:27:44
, ajm293, 2020-05-11 , 10:27:41
, ajm293, 2020-05-11 , 10:27:42
, ajm293, 2020-05-11 , 10:27:43
, ajm293, 2020-05-11 , 10:28:30
, ajm293, 2020-05-11 , 10:28:32
, ajm293, 2020-05-11 , 10:28:36
, ajm293, 2020-05-11 , 10:28:33
, ajm293, 2020-05-11 , 10:28:30
, ajm293, 2020-05-11 , 10:28:31
, ajm293, 2020-05-11 , 10:28:31
, ajm293, 2020-05-11 , 10:28:32
, ajm293, 2020-05-11 , 10:28:32
, ajm293, 2020-05-11 , 10:29:01
, ajm293, 2020-05-11 , 10:29:24
, ajm293, 2020-05-11 , 10:29:24
, ajm293, 2019-12-10 , 14:51:32
, ajm293, 2019-12-10 , 14:56:26
, ajm293, 2019-12-10 , 14:56:24
, ajm293, 2019-05-23 , 07:48:45
, ajm293, 2019-12-10 , 14:51:32
, ajm293, 2020-05-14 , 14:54:38

can you help me output exactly what i see from the console rather than all this info?

thanks
 


From looking at the above, I think you may have the code a little confused.

Your first code snippet:
Bash:
find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf "ajm293, %TY-%Tm-%Td , %TT\n , " | sort -nr | head -n 1
Syntactically is OK.
What it does is for each file, or directory found by find, it prints the following:
ajm293, {file modify date}, {modify timestamp}{newline},
Which will appear onscreen as:
Code:
ajm293, 2020-05-21, 13:44:22.848235
,
Then the next record is written out after the comma.

And after find has used output the time-stamp information of all found files/directories, you're piping the output to sort the timestamps in order from newest to oldest and then using head to show only the most recent time-stamp.

So, as things stand - the line output for the very first file found will have this printed:
ajm293, 2020-05-21, 13:44:22.848235

The second result onwards would be written out (on separate lines) as:
,ajm293, 2020-05-21, 13:44:23.943433

So your output from that command is going to be inconsistent.
If the first file/directory found by find is also the most recent, the output will look slightly different to if any of the others were more recent.

But you can make the output the same for all results if you switch the position of the comma and the newline in finds -printf:
e.g.
Bash:
find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf "ajm293, %TY-%Tm-%Td , %TT,\n" | sort -nr | head -n 1

That way each record will look like this:
ajm293, {date}, {timestamp},{newline}
or onscreen:
ajm293, 2020-05-21, 13:44:22.848235,

That fixes the first part of your post. Now all of the lines that are output by find will have exactly the same structure, before they are sorted and the newest is displayed.

With the second part of your post:
Code:
find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf >> /nas/quota/slot_2/root_vdm_2/homeshare/home/jltest/output.csv "ajm293_%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1
This will not do what you want. The append file redirection >> is being done in the wrong place. The redirection should be AFTER the head command.
e.g.
Code:
find /nas/quota/slot_2/root_vdm_2/homeshare/home/username/ -printf "ajm293_%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1 >> /nas/quota/slot_2/root_vdm_2/homeshare/home/jltest/output.csv

That will append the record for the most recent timestamp to the output file.
 
could I ask a little help please.
Im trying to output the number of child folders there are in a given root folder, the below example work and outputs the correct figure for the lht204 folder

When I run this
Bash:
find /nas/quota/slot_2/root_vdm_2/isadhomes07/home/lht204 -mindepth 1 -maxdepth 100000 -type d | wc -l >> /nas/quota/slot_2/root_vdm_2/isadhomes02/home/jltest/output_isadhomes07_foldercount.csv

I would like to expand on this and output to csv creating a new line for each bash line I run, when i try the below i get an error:

Bash:
find /nas/quota/slot_2/root_vdm_2/isadhomes07/home/lht204 -mindepth 1 -maxdepth 100000 -type d | wc -l / -printf "lht204, %TY-%Tm-%Td ,  %TT ,  ISADHOMES07\n" | sort -nr | head -n 1 >> /nas/quota/slot_2/root_vdm_2/isadhomes02/home/jltest/output_isadhomes07_foldercount.csv

I get this output

wc: invalid option -- 1
Try `wc --help' for more information.

Thanks
Jim
 
Try... wc -l (lowercase L, not a one)
 
Good point, they look very similar in the shell, trued this (lower cas l) and i get this:

Bash:
find /nas/quota/slot_2/root_vdm_2/isadhomes07/home/lht204 -mindepth 1 -maxdepth 100000 -type d | wc -l / -printf "lht204, %TY-%Tm-%Td ,  %TT ,  ISADHOMES07" | sort -nr | head -n l >> /nas/quota/slot_2/root_vdm_2/isadhomes02/home/jltest/output_isadhomes07_foldercount.csv


wc: invalid option -- p
Try `wc --help' for more information.
head: l: invalid number of lines
 

Members online


Top