Time in filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time in filename
# 8  
Old 02-26-2018
Quote:
Originally Posted by Don Cragun
That isn't an answer. You said the format of your filenames is:
Code:
abcd_deft_2018-02-21_100012
abcd_mnpo_2018-02-21_100020

but your code looks for filenames ending with .txt. Which form is correct? Is there a .txt at the end of your filenames or not?
Yes, the type of file is txt and as I mentioned the name of files are different.


Quote:
Originally Posted by Don Cragun
Show us the output from the command:
Code:
ls -l /opt/abc/Output/*2018-02-21_10*

Files are there in 'Output' directory, here is result:
Code:
abcd_part_2018-02-21_100004.txt
mnpg_part_2018-02-21_100012.txt
fdop_part_2018-02-21_100026.txt
cdpm_part_2018-02-21_100120.txt
abcd_part_2018-02-21_100135.txt


Quote:
Originally Posted by Don Cragun
What are you trying to do? Are you trying to put all files matching a pattern found in a local directory into a directory on a remote system? Or, are you trying to get all files matching a pattern found in a directory on a remote system into a local directory?
Please read my post one more time, in code you can see that I'm using PUT to send files matching a pattern in local directory to the remote server.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!


---------- Post updated at 04:01 AM ---------- Previous update was at 03:42 AM ----------

Quote:
Originally Posted by RudiC
It's not quite clear WHAT you tested, and what files / directories are available.

Quote:
Originally Posted by RudiC
Does abcd_part_2018-02-23_100004 exist in your local directory, or is it abcd_part_2018-02-23_100004.txt?
YES,abcd_part_2018-02-23_100004.txt exists in my local directory.

Quote:
Originally Posted by RudiC
Does LOCALPATH='/opt/abc/Output' exist?
YES.

Quote:
Originally Posted by RudiC
What's its contents?
The text files that I'm trying to send via FTP
The files exist, the directory exists. My problem is how to write the correct pattern to select daily files which has been created at 10 am(whatever for minute and second) and put them in remote server.

Last edited by RudiC; 02-26-2018 at 04:48 AM.. Reason: Added CODE tags.
# 9  
Old 02-26-2018
Quote:
Originally Posted by Home
Yes, the type of file is txt and as I mentioned the name of files are different.
You said "YES, they are there, all files." which does not say they are of type text and does not clearly state whether or not your files' names end with .txt or not.
Quote:
Files are there in 'Output' directory, here is result:
Code:
abcd_part_2018-02-21_100004.txt
mnpg_part_2018-02-21_100012.txt
fdop_part_2018-02-21_100026.txt
cdpm_part_2018-02-21_100120.txt
abcd_part_2018-02-21_100135.txt




Please read my post one more time, in code you can see that I'm using PUT to send files matching a pattern in local directory to the remote server.
I can see what your code does and I can see that with the above listed files, your code will not work. But, since we don't have a clear statement of what you are trying to do, it is hard to guess at what should be done to fix your code. The code you showed us asking for a pattern to be inserted to fix it:
Code:
put abcd_part_$DATE_(What should i write here?).txt

has three possible answers to what you should write there depending on whether you want to transfer the first matching file, the second matching file, or both matching files. (Note that the put command will only transfer one file; not two. Note also that there are no files for some of the patterns you're passing to put which will generate what I would assume would be unneeded diagnostic messages.

So, I repeat. What are you trying to do? Do you want to move all of the files with the proper timestamp? Or, if there is more than one file with a given initial part of the pattern with different timestamps, do you just want to send the first of that base name or the last of that base name? Are you expecting to get at least one (or exactly one) file matching each of your initial file base name patterns during that hour every day?

If you want to send all of the files (which is not what your script is trying to do), you could try replacing all of the puts in your script with the single command:
Code:
mput *_$DATE_10????.txt

Quote:
Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
And, as the moderator said when fixing your post, please use CODE tags when displaying sample input, output, and code segments.
# 10  
Old 02-26-2018
Quote:
Originally Posted by Don Cragun
You said "YES, they are there, all files." which does not say they are of type text and does not clearly state whether or not your files' names end with .txt or not.
As I mentioned before they are text file which ends with
Code:
.txt

as type of file.
The last file name is missing 'e'. All daily files have different name but everyday the same files would be created(minute and second are not important).

Code:
abcd_part_2018-02-26_100004.txt
mnpg_part_2018-02-26_100012.txt
fdop_part_2018-02-26_100026.txt
cdpm_part_2018-02-26_100120.txt
abcde_part_2018-02-26_100135.txt

Quote:
Originally Posted by Don Cragun
What are you trying to do?
Sending some text files to a remote server by ftp. Files are created daily at 10 am.

Quote:
Originally Posted by Don Cragun
Do you want to move all of the files with the proper timestamp? Or, if there is more than one file with a given initial part of the pattern with different timestamps, do you just want to send the first of that base name or the last of that base name?
As I wrote, daily files have different name, but they differ in timestamp.

Quote:
Originally Posted by Don Cragun
Are you expecting to get at least one (or exactly one) file matching each of your initial file base name patterns during that hour every day?
YES. Then the script should find 5 match(above files) in directory and send them via ftp.
In the directory where the files are located there are more than 300 files with the same name but different date and time and I want to send only daily files, then I can't run your suggested command.
# 11  
Old 02-26-2018
Still: replace put with mput as put doesn't seem to accept wildcard chars. The man page is a bit vague here, while it clearly mentions wildcards for the mput command. Not sure, though, what the "here document" does to the wildcards...

EDIT: Does this help?
Code:
. . . <<EOF
. . . 
mput $(ls ????_part_2018-02-26_10????.txt)
EOF

# 12  
Old 02-26-2018
You might need to mangle this. I would suspect that the shell will want to expand/interpolate the ? wildcard and you want to avoid that and pass it into the ftp command as literal text. Of course, you will want $DATE to be interpolated so you might have to end up with something ugly like this:-
Code:
mput \?\?\?\?_part_${DATE}_10\?\?\?\?.txt

Not pretty, but it might do the job. An alternate contrived way might be to use single quotes, but of course you have to still allow $DATE to be interpolated, so you get the confusing looking:
Code:
mput '????_part_'$DATE'_10????.txt'

A further alternative might be to set a variable early and use that, allowing the shell to interpolate it into what you want:-
Code:
:
:
q4='????'     #  Note single quotes
ftp ........  # whatever
:
:
mput ${q4}_part_${DATE}_10${q4}.txt
:
:

If you let the shell expand everything, then you might end up with an invalid command depending on how mput is provided on your client. Some clients don't like mput fileA fileB fileC whilst accepting mput file? so have a look at the description in the (client side) manual page for ftp and also if you fire up the ftp command, you should be able to use help mput from there too. That might clarify things.



I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract date and time part from filename

Hi, I am facing one scenario in which I need to extract exact position of date and time from the name of the files. For example, Below is the record in which I need to extract position of YYYYMMDD,HHMISS and YYMMDD. Date and time variables can come more than once. I need to use these position... (13 Replies)
Discussion started by: Prathmesh
13 Replies

2. 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

3. Shell Programming and Scripting

Validate date and time in filename by awk

hi i want to validate the date and time in filename filename : mohan.moh.ccyymmdd.ccyymmdd.hhmmss.txt mohan_moh.20151222.20151222.122442.txt i want code that check that date given in filename 20151222 in this format ccyymmdd else it mark file is not valid used in my OS detail is AIX 6... (12 Replies)
Discussion started by: MOHANP12
12 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Shell Scripts - Append a filename with date and time....

Hello, I need to create a shell script that appends a filename to create a name with the date and time appended that is guaranteed to not exist. That is, the script insures you will not overwrite a file with the same name. I am lost with this one. I know I need to use date but after that I am... (3 Replies)
Discussion started by: citizencro
3 Replies

6. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

7. Shell Programming and Scripting

change the filename by adding up 1 each time, tricky one

:confused: Hi, I posted here before for adding up of datafile name each time, here is an example: #!/bin/bash cutdfname="data11.dbf" newname=$(echo "${cutdfname}" |tr "" "" |tr "#_@-" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |tr -s "x") num=$(echo $newname |cut -d"." -f1|awk... (5 Replies)
Discussion started by: netbanker
5 Replies

8. UNIX for Advanced & Expert Users

find formatted filename with date time

Hi, I operate and use HF radars along the California coast for ocean surface currents. The devices use Mac OS as the control and logging software. The software generates thousands of files a week and while I've used PERL in the past to solve the problems of finding files I come to realize some... (6 Replies)
Discussion started by: dpath2o
6 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question