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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print the specific part of the file name with file creation date?
# 1  
Old 01-18-2018
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.


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

Output is :

Code:
 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 :

Code:
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

Moderator's Comments:
Mod Comment Please use CODE tags (for data as well!) as required by forum rules!

Last edited by rbatte1; 01-18-2018 at 10:12 AM.. Reason: Added CODE tags.
# 2  
Old 01-18-2018
Code:
v=20171228 ; find . -type f -name "MobileProtocol.${v}T*" -printf '%TY-%Tm-%Td '${v}'\n'| sort | uniq -c

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 01-18-2018
Try
Code:
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

This User Gave Thanks to RudiC For This Post:
# 4  
Old 01-18-2018
here is the output now i am getting:

Code:
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:

Code:
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.

Last edited by rbatte1; 01-18-2018 at 10:14 AM..
# 5  
Old 01-18-2018
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
Code:
MobileProtocol.20171228T154200.157115.udr
                                 11111
                        12345678901234

filename?

Last edited by RudiC; 01-18-2018 at 10:24 AM..
This User Gave Thanks to RudiC For This Post:
# 6  
Old 01-18-2018
Quote:
What if I have multiple files with different pattern at the same place.
How will I implement that.
Code:
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


Last edited by rdrtx1; 01-18-2018 at 10:21 AM..
# 7  
Old 01-18-2018
@RudiC:
Code:
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 ----------

Code:
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.


Moderator's Comments:
Mod Comment Thanks for trying to use tags - but don't "overtag". Your own text goes untagged, QUOTE tags for text cited from other sources.

Last edited by RudiC; 01-18-2018 at 10:32 AM.. Reason: Removed or changed QUOTE to CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to print file name and its creation date

Hello , I am looking for a script to print file name and its last updated time. FILE CREATION-TIME FILE-NAME 24/10/2017 12:34 TDR-IU-8-2017.10.24.07:40:00-2017.10.24.07:45:00 when we run l command it print the directory and the files with details like permission,... (1 Reply)
Discussion started by: sadique.manzar
1 Replies

2. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

3. Shell Programming and Scripting

Help with creating a text file in perl with file creation date.

Hi, I am quite new to Perl scripting and i need to create a .TXT file using perl, with fields (A,B,C,D,E), and this text file should be named with current file creation date "XYZ_CCYYMMDD.TXT" (i.e.XYZ_2011042514:33 PM). Can anyone who has done this, please share their expertise on this... (5 Replies)
Discussion started by: msrahman
5 Replies

4. Shell Programming and Scripting

finding creation date of a file

Hi, Can anyone tell me a process to find the creation date of a file in a directory. If suppose I have a file in a directory created in 2009 -rw-r--r-- 1 xyz guest 2480 Jul 16 2009 sample.txt The command should return the the file creation date as 16/07/2009 thanks, (2 Replies)
Discussion started by: swathich
2 Replies

5. Shell Programming and Scripting

how to find creation date of file

Hi, I just need to know way of getting date of file when it was created. eg i have a file abc created on 23 aug. Now i need to know date of file i.e. 23 aug. How can i get that data. Thanks Sarbjit (7 Replies)
Discussion started by: sarbjit
7 Replies

6. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

7. Shell Programming and Scripting

How to get File creation date.

Hi All, I need to get file creation date. I have to access one file who's name is like... abc.log092308 and the date changes as per current date. And i am accessing this file next day. meance in above case i will access above file on 09-24-2008 Also one problem is that this file... (2 Replies)
Discussion started by: Jeevan Salunke
2 Replies

8. UNIX for Dummies Questions & Answers

Changing Creation Date to a Prespecified Date of a File In Unix

Dear Expert, Is there a command to do that in Unix? In such a way that we don't need to actually "write" or modified the content. -- monkfan (4 Replies)
Discussion started by: monkfan
4 Replies

9. UNIX for Dummies Questions & Answers

file creation date & time

Hi All, I have some files which are creates every day using a script. I want to create a log files which does write "filename,creation day and time" how can I do this ?? Alice (3 Replies)
Discussion started by: alisevA3
3 Replies

10. UNIX for Advanced & Expert Users

file creation date including seconds

Hi, Is anybody can help me to get the file creation date with seconds? -rw-r--r-- 1 opsc system 422550845 Aug 22 15:41 StatData.20020821 Thanks in advance Krishna (7 Replies)
Discussion started by: krishna
7 Replies
Login or Register to Ask a Question