Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 889  / 2 Years ago, fri, may 20, 2022, 10:33:59

I am trying to write a CSH script that will look at components of the filename to generate a date/time. The problem is, I have no idea how to extract part of a filename to use it. Here is a sample filename:



nam_218_20140126_1800_001.grb  


20140126 is the date portion of the filename and 1800 is the time. I need to extract it and convert it to 2014-01-26_18:00:00 for use in an environment variable. Any hints?



Thanks


More From » scripts

 Answers
2
% set filename='nam_218_20140126_1800_001.grb' 
% set datetime=`echo "$filename" | sed -r 's/.*_([0-9]{4})([0-9]{2})([0-9]{2})_([0-9]{2})([0-9]{2}).*/1-2-3_4:5:00/'`
% echo $datetime
2014-01-26_18:00:00

[#27241] Saturday, May 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rmiend

Total Points: 292
Total Questions: 101
Total Answers: 111

Location: Azerbaijan
Member since Tue, Aug 9, 2022
2 Years ago
rmiend questions
Tue, Jan 18, 22, 23:52, 2 Years ago
Sat, Sep 17, 22, 15:44, 2 Years ago
;