We want to show each file's modified date and time when applying grep
to selected files by the find
command. The final result should look like:
2016-10-17 Mon 20:38:57 ./rest/47results.php: 5 :σχόλια, ιδέες facebook
Running the following from 47test.php file:
system('export TZ=":Europe/Athens"; find . -name "*.*" \
-not \( -path ./admin -prune \) \
-not \( -path ./people/languages -prune \) \
-not \( -path ./include -prune \) \
-type f -mmin -10 \
-printf "%TY-%Tm-%Td %Ta %TH:%TM:%TS %p\n" \
-exec grep -HTni "σχόλια" {} + ');
we get distinct lines printed for each modified file and each line:
2016-10-17 Mon 21:09:55.0000000000 ./47test.php
2016-10-17 Mon 20:40:30.0000000000 ./places/00testout.txt
2016-10-17 Mon 20:38:57.0000000000 ./rest/47results.php
./47test.php: 22 :-exec grep -HTni "σχόλια" {} + ');
./rest/47results.php: 5 :σχόλια, ιδέες facebook
./rest/47results.php: 6 :σχόλια, ιδέες twitter
./rest/47results.php: 7 :Τα σχόλια σας
One for each find
and one for each grep
result.
As mentioned in the beginning, how can one print sorted, combined results in just one line for each grep
?
2016-10-17 Mon 21:09:55 ./47test.php 22 :-exec grep -HTni "σχόλια" {} + '); 2016-10-17 Mon 20:38:57 ./rest/47results.php: 5 :σχόλια, ιδέες facebook 2016-10-17 Mon 20:38:57 ./rest/47results.php: 6 :σχόλια, ιδέες twitter 2016-10-17 Mon 20:38:57 ./rest/47results.php: 7 :Τα σχόλια σας
You can use this
find+grep
combination to get the formatted result:\06
as field delimiter to address filenames/paths with whitespaces/newlines etc.\0
(NULL) is used as line terminator for the same reason.%.2TS
is used to trip fractional part of the second value.sed
is used to insert date/time at line start ofgrep
output.PHP Code: