How to print the specific part of the file name with file creation date?

Hello Folks,

I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern.

Filename: MobileProtocol.20171228T154200.157115.udr

I want to get the count of files created on each day based on a pattern find.

find . -type f -name "MobileProtocol.20171228T*" -printf '%TY-%Tm-%Td\n'|sort | uniq -c

Output is :

 1686 2017-12-28 
 287 2017-12-30
   1 2018-01-01
   1 2018-01-02
   2 2018-01-03
   1 2018-01-05
   2 2018-01-06
   3 2018-01-07
   1 2018-01-08
   1 2018-01-09
   1 2018-01-10
  35 2018-01-11

I want print pattern of the files too in my script.
Kindly guide and help me.

Output looking for is :

1686 2017-12-28 20171228  <--- from file pattern
 287 2017-12-30 20171228
   1 2018-01-01 20171228
   1 2018-01-02 20171228
   2 2018-01-03 20171228
   1 2018-01-05 20171228
   2 2018-01-06 20171228
   3 2018-01-07 20171228
   1 2018-01-08 20171228
   1 2018-01-09 20171228
   1 2018-01-10 20171228
  35 2018-01-11 20171228
v=20171228 ; find . -type f -name "MobileProtocol.${v}T*" -printf '%TY-%Tm-%Td '${v}'\n'| sort | uniq -c
1 Like

Try

find . -type f -name "MobileProtocol.20171228T*" -printf '%TY-%Tm-%Td %p\n' | sed -r 's/T[0-9.]{14}udr//; s/ .*\./ /;' | sort -k1,1 | uniq -cw10
1 Like

here is the output now i am getting:

1649 2017-12-28 20171228
 499 2017-12-30 udr
   1 2017-12-31 udr
   1 2018-01-01 udr
   1 2018-01-02 udr
   1 2018-01-05 udr
   1 2018-01-07 udr
   2 2018-01-10 udr
   5 2018-01-11 udr

---------- Post updated at 08:31 AM ---------- Previous update was at 08:17 AM ----------

What if I have multiple files with different pattern at the same place.
How will I implement that.

---------- Post updated at 08:39 AM ---------- Previous update was at 08:31 AM ----------

@RudiC and @ rdrtx1 Please reply.

@RudiC your command is giving the output like below:

1649 2017-12-28 20171228
499 2017-12-30 udr
1 2017-12-31 udr
1 2018-01-01 udr
1 2018-01-02 udr
1 2018-01-05 udr
1 2018-01-07 udr
2 2018-01-10 udr
5 2018-01-11 udr

Where I want 20171228 instead of every udr.
Kindly guide.

For Heaven's sake! My crystal ball is broken again! How can I see sadique.manzar's "multiple files with different pattern" now? How can I help him/her? And how and why can I find out why my [0-9.]{14} pattern doesn't match his/her

MobileProtocol.20171228T154200.157115.udr
                                 11111
                        12345678901234

filename?

1 Like
patterns="20171228 20171229"
for pattern in $patterns
do
   find . -type f -name "MobileProtocol.${pattern}T*" -printf '%TY-%Tm-%Td '${pattern}'\n'| sort | uniq -c
done

@RudiC:

MobileProtocol.20171228T083500.18575.udr
MobileProtocol.20171228T043000.9955.udr
MobileProtocol.20171228T230700.103907.udr
MobileProtocol.20171228T095500.21219.udr
MobileProtocol.20171228T130000.156953.udr
MobileProtocol.20171228T182400.15272.udr
MobileProtocol.20171228T182500.15273.udr
MobileProtocol.20171228T082000.29941.udr
MobileProtocol.20171228T081800.156671.udr
MobileProtocol.20171228T082000.156673.udr
MobileProtocol.20171228T081900.156672.udr
MobileProtocol.20171228T151500.10084.udr
MobileProtocol.20171228T065000.26870.udr
MobileProtocol.20171228T170200.60932.udr
MobileProtocol.20171228T165400.60924.udr
MobileProtocol.20171228T165700.60927.udr
MobileProtocol.20171228T235900.104040.udr
MobileProtocol.20171228T125800.60688.udr
MobileProtocol.20171228T130000.60690.udr
MobileProtocol.20171228T125900.60689.udr

when i adjust the value [0-9.]{14} like 14 to 12 13 i get results for different pattern like "20171224" "20171227" and so on so how could i predict this value in general. ?
---------- Post updated at 09:24 AM ---------- Previous update was at 09:20 AM ----------

find . -type f -name "MobileProtocol.20171228T*" -printf '%TY-%Tm-%Td %p\n' | sed -r 's/T[0-9.]{13}udr//; s/ .*\./ /;' | sort| uniq -cw10

 1590 2017-12-28 20171228
  499 2017-12-30 20171228
    1 2017-12-31 20171228
    1 2018-01-01 20171228
    1 2018-01-03 20171228
    2 2018-01-05 20171228
    2 2018-01-06 20171228
    3 2018-01-07 20171228
    1 2018-01-11 20171228


 find . -type f -name "MobileProtocol.20171224T*" -printf '%TY-%Tm-%Td %p\n' | sed -r 's/T[0-9.]{12}udr//; s/ .*\./ /;' | sort| uniq -cw10

     2 2017-12-23 20171224
  2124 2017-12-24 20171224
     1 2017-12-27 20171224
     2 2017-12-31 20171224

how will i predict {12}udr in case for files pattern.

man regex :

Try T[0-9.]{12,14}udr for the regex. Or T([0-9]{4,6}\.){2}udr .

And, PLEASE become accustomed to describe your problem with utmost care, precision, and detail.