Extract date and time part from filename


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract date and time part from filename
# 8  
Old 04-10-2019
Quote:
Originally Posted by RudiC
Hmmmm - not quite clear yet when you want the dots, and when the printf format strings, or when both... See how far this gets you:



Code:
awk '
FNR == 1        {FILENR++
                }
FILENR <= 2     {CNT++
                 CHFM[CNT] = $1
                 RGEX[CNT] = $2
                 DOTS[CNT] = $3
                 FMTS[CNT] = $4
                 next
                }
                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         for (i=1; i<=CNT; i++) if (match (TMP, CHFM[i]))       {printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, CHFM[i], DOTS[i], FMTS[i]
                                                                                                 TMP = substr (TMP, RSTART+RLENGTH)
                                                                                                 PTR += RSTART + RLENGTH - 1
                                                                                                }
                                        }
                 print ""
                }
'  FS=","  *format.csv FS="|" OFS="|" RECORD
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S

Thanks RudiC. This works perfectly well for me.
If I can ask for one more thing that arise with this result. Now, with the same three input files RECORD, date_format.csv and timestamp_format.csv, I need to group how many dates are in column 4 and 5.

For example, If the RECORD file has records -
Code:
$ cat RECORD
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY
$

Output should be -
Code:
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|2|1|1|1
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|1|1|1|1

where,
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEG ORY and SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY represents the input record.

Next 2 columns 2|1|1|1 represents, number of date and time fields which is part of date_format.csv and timestamp_format.csv in fields ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt and P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv i.e. column 4 of input file RECORD.
and Next 2 1|1|1|1 columns represents, number of date and time fields which is part of date_format.csv and timestamp_format.csv in fields ABC_123_V01P.YYYYMMDD.HHMISS.txt and Report.ABCD_csv.YYYYMMDD.HHMISS.csv i.e. column 5 of input file RECORD.
# 9  
Old 04-11-2019
So you want to print out info ACROSS lines, i.e. in line 1 should appear info about field 4 of line 1 and 2, and in line2 there should be info on field 5 of line 1 and 2? What if more lines will appear, i.e. line3, line 4, etc.? Where and how should those infos be printed?
# 10  
Old 04-11-2019
Quote:
Originally Posted by RudiC
So you want to print out info ACROSS lines, i.e. in line 1 should appear info about field 4 of line 1 and 2, and in line2 there should be info on field 5 of line 1 and 2? What if more lines will appear, i.e. line3, line 4, etc.? Where and how should those infos be printed?

Hi RudiC,

Let me explain why and what I am looking exactly.

For input file RECORD, earlier code provided by you provides below output -

Input File -
Code:
$ cat RECORD
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY
$

Output -
Code:
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S

Here, As you can see in input file for 1st record column 4 filename is ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt which contains 2 date values (as specified in date_format.csv) and 1 time value (as specified in timestamp_format.csv).
For 2nd record column 4 filename is P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv which contains 1 date value (as specified in date_format.csv) and 1 time value (as specified in timestamp_format.csv).

Similarly, For column 5 we have different number of date/time values. Which results in different number of columns in output depending on number of date/time values in filename. Hence, It is difficult to identify exact position of date/time variables for column 4 and 5.

For this reason, I was thinking of adding 4 more columns in output which will help me to identify how much date/time variables present in column 4 and 5.
Code:
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|2|1|1|1
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|1|1|1|1

Here, For 1st output record, 2|1|1|1
-- 2 represents number of date variables in columns 4 as specified in date_format.csv
-- 1 represents number of time variables in columns 4 as specified in timestamp_format.csv
-- 1 represents number of date variables in columns 5 as specified in date_format.csv
-- 1 represents number of time variables in columns 5 as specified in timestamp_format.csv
For 2nd output record, 1|1|1|1
-- 1 represents number of date variables in columns 4 as specified in date_format.csv
-- 1 represents number of time variables in columns 4 as specified in timestamp_format.csv
-- 1 represents number of date variables in columns 5 as specified in date_format.csv
-- 1 represents number of time variables in columns 5 as specified in timestamp_format.csv

Hope this clarifies why I am looking for this. It will be even better if we can use our earlier code and produce output as below -
Code:
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|2|1|1|1|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|1|1|1|1|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S

Here, column 7,8,9 and 10 will serve the same purpose as mentioned above to represent number of date/time variables in column 4 and 5 respectively.
# 11  
Old 04-11-2019
That's much clearer, thank you. How about (adding the new fields at the end, so we can print the format info as we go through the file)
Code:
awk '
FNR == 1        {FILENR++
                }

FILENR <= 2     {CNT++
                 CHFM[CNT] = $1
                 RGEX[CNT] = $2
                 DOTS[CNT] = $3
                 FMTS[CNT] = $4
                 FIDX[CNT] = FILENR
                 next
                }

                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         for (i=1; i<=CNT; i++) if (match (TMP, CHFM[i]))       {printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, CHFM[i], DOTS[i], FMTS[i]
                                                                                                 TMP = substr (TMP, RSTART+RLENGTH)
                                                                                                 PTR += RSTART + RLENGTH - 1
                                                                                                 TYP[j-3,FIDX[i]]++
                                                                                                }
                                        }
                 for (j=1; j<=2; j++) printf "|%s|%s", TYP[j,1], TYP[j,2]
                 print ""
                 split ("", TYP)
                }
'  FS=","  file[45] FS="|" OFS="|" file3

This User Gave Thanks to RudiC For This Post:
# 12  
Old 04-11-2019
Quote:
Originally Posted by RudiC
That's much clearer, thank you. How about (adding the new fields at the end, so we can print the format info as we go through the file)
Code:
awk '
FNR == 1        {FILENR++
                }

FILENR <= 2     {CNT++
                 CHFM[CNT] = $1
                 RGEX[CNT] = $2
                 DOTS[CNT] = $3
                 FMTS[CNT] = $4
                 FIDX[CNT] = FILENR
                 next
                }

                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         for (i=1; i<=CNT; i++) if (match (TMP, CHFM[i]))       {printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, CHFM[i], DOTS[i], FMTS[i]
                                                                                                 TMP = substr (TMP, RSTART+RLENGTH)
                                                                                                 PTR += RSTART + RLENGTH - 1
                                                                                                 TYP[j-3,FIDX[i]]++
                                                                                                }
                                        }
                 for (j=1; j<=2; j++) printf "|%s|%s", TYP[j,1], TYP[j,2]
                 print ""
                 split ("", TYP)
                }
'  FS=","  file[45] FS="|" OFS="|" file3

Thanks RudiC. Adding new fields at the end will work too.
But, I am not getting desired output for below input -
Code:
$ cat RECORD
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.XXXXXXXXXX.txt|ABC_123_V01P.YYYY-MM-DD.YYYYMMDD.HHMISS.XXXXXXXXXX.txt|CATEGORY
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY
$

Getting below output -
Code:
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|2|1|1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|2||1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.XXXXXXXXXX.txt|ABC_123_V01P.YYYY-MM-DD.YYYYMMDD.HHMISS.XXXXXXXXXX.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|51|10|XXXXXXXXXX|..........|%s|25|8|YYYYMMDD|........|%Y%m%d|41|10|XXXXXXXXXX|..........|%s|2|1|1|1
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|1|1|1|1

# 13  
Old 04-11-2019
Good grief! What a heck of a problem. We have a "race condidtion" of what pattern occurs first in the pattern file and what occurs first in the string. When found a pattern, and reduced the string, we need to start over with the first pattern again. I think I have found a solution; try and report back:
Code:
FNR == 1        {FILENR++
                }

FILENR <= 2     {CHFM = CHFM DL $1
                 RGEX[$1] = $2
                 DOTS[$1] = $3
                 FMTS[$1] = $4
                 FIDX[$1] = FILENR
                 DL = "|"
                 next
                }

                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         while (match (TMP, CHFM))      {MTCH = substr (TMP, RSTART, RLENGTH)
                                                                         printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, MTCH, DOTS[MTCH], FMTS[MTCH]
                                                                         TMP = substr (TMP, RSTART+RLENGTH)
                                                                         PTR += RSTART + RLENGTH - 1
                                                                         TYP[j-3,FIDX[MTCH]]++
                                                                        }
                                        }
                 for (j=1; j<=2; j++) printf "|%s|%s", TYP[j,1]+0, TYP[j,2]+0
                 print ""
                 split ("", TYP)
                }
'  FS=","  file[45] FS="|" OFS="|" file3
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|2|1|1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|33|6|HHMISS|......|%H%M%S|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|3|1|1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.XXXXXXXXXX.txt|ABC_123_V01P.YYYY-MM-DD.YYYYMMDD.HHMISS.XXXXXXXXXX.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|33|6|HHMISS|......|%H%M%S|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|51|10|XXXXXXXXXX|..........|%s|14|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|25|8|YYYYMMDD|........|%Y%m%d|34|6|HHMISS|......|%H%M%S|41|10|XXXXXXXXXX|..........|%s|3|2|2|2
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|1|1|1|1


Last edited by RudiC; 04-11-2019 at 10:46 AM..
These 2 Users Gave Thanks to RudiC For This Post:
# 14  
Old 04-11-2019
Quote:
Originally Posted by RudiC
Good grief! What a heck of a problem. We have a "race condidtion" of what pattern occurs first in the pattern file and what occurs first in the string. When found a pattern, and reduced the string, we need to start over with the first pattern again. I think I have found a solution; try and report back:
Code:
FNR == 1        {FILENR++
                }

FILENR <= 2     {CHFM = CHFM DL $1
                 RGEX[$1] = $2
                 DOTS[$1] = $3
                 FMTS[$1] = $4
                 FIDX[$1] = FILENR
                 DL = "|"
                 next
                }

                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         while (match (TMP, CHFM))      {MTCH = substr (TMP, RSTART, RLENGTH)
                                                                         printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, MTCH, DOTS[MTCH], FMTS[MTCH]
                                                                         TMP = substr (TMP, RSTART+RLENGTH)
                                                                         PTR += RSTART + RLENGTH - 1
                                                                         TYP[j-3,FIDX[MTCH]]++
                                                                        }
                                        }
                 for (j=1; j<=2; j++) printf "|%s|%s", TYP[j,1]+0, TYP[j,2]+0
                 print ""
                 split ("", TYP)
                }
'  FS=","  file[45] FS="|" OFS="|" file3
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|2|1|1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|33|6|HHMISS|......|%H%M%S|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S|3|1|1|1
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDD.HHMISS.YYYY-MM-DD.XXXXXXXXXX.txt|ABC_123_V01P.YYYY-MM-DD.YYYYMMDD.HHMISS.XXXXXXXXXX.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|33|6|HHMISS|......|%H%M%S|40|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|51|10|XXXXXXXXXX|..........|%s|14|10|YYYY-MM-DD|....-..-..|%Y-%m-%d|25|8|YYYYMMDD|........|%Y%m%d|34|6|HHMISS|......|%H%M%S|41|10|XXXXXXXXXX|..........|%s|3|2|2|2
SOURCE|LOGIN|SERVER|P_XYZ_1234_ABCD.YYYYMMDD.HHMISS.csv|Report.ABCD_csv.YYYYMMDD.HHMISS.csv|CATEGORY|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|17|8|YYYYMMDD|........|%Y%m%d|26|6|HHMISS|......|%H%M%S|1|1|1|1

Thank you so much RudiC for your valuable time and help. Solution works perfectly fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract date and time from filename?

Hi, I'm totally new in sell script and working with a shell code. I want to extract the date and time from the filenames. The filenames are different but all of them begins with WI_ SCOPE_: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt... (5 Replies)
Discussion started by: Home
5 Replies

2. UNIX for Dummies Questions & Answers

Extract Date part from the filename

Hi All, I have incoming source files abcmmyy.txt I need to extract the mmyy part from the filename and pass that to a variable . I really appreciate your quick response on this. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

3. Shell Programming and Scripting

Extract a part of a filename containing a particular word

Hi All, Thanks in Advance Shell Script or Perl Script I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv... (7 Replies)
Discussion started by: aealexanderraj
7 Replies

4. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

5. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

6. Shell Programming and Scripting

append a filename with system date and time

Hi, There are similar kind of posts, but none seems like working for me. Please correct me if I'm wrong. I need append/rename file abc.txt with file processed date and time like abc_systemdatetimestamp.txt and move it to different folder. for example I have /source/data/abc.txt ... (1 Reply)
Discussion started by: amsn08
1 Replies

7. Shell Programming and Scripting

Extract date from filename and set timestamp

I have lots of files in this format: dvgrab-2003.06.29_15-30-24.mpg The numbers represents the date and time (YYYY.MM.DD_HH-MM-SS) How can I extract the dates from the filenames, and use the dates in the file timestamp? I guess this can be done by using "find", "sed" and "touch"? Can... (6 Replies)
Discussion started by: qwerty1234
6 Replies

8. Shell Programming and Scripting

how to update date part with new increment date time

hi experts, my requirement is like this i need to develop a shell script to update date part with new incremental date time in file some 'X' which is kept at some server location incrementing every two hours.as i am new to this scripting i need support from u people,thanx in advance (1 Reply)
Discussion started by: amanmro
1 Replies

9. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 Replies

10. UNIX for Dummies Questions & Answers

Insert date/time within a filename

Hi Guys, I need to script the renaming of files as followins: files: firstjd secondjo thirdjv My script needs to insert the date/time infront of the last 2 characters of the filenames above, any ideas greatly received :) the letters before the last 2 characters could change, I'm only... (7 Replies)
Discussion started by: cooperman
7 Replies
Login or Register to Ask a Question