Move txt file to with current date appended to filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Move txt file to with current date appended to filename
# 8  
Old 12-08-2011
what you're asking for doesn't sound simple in any language, really. How's it supposed to tell the 'c' apart from the 'orders'? What if there's a file 'ordera.txt' as well, should it group them into order1/2/3/4 instead of order1, orders1/2/3? etc, etc. There's plenty of ambiguities.

But if just grouping on the last letter will do...

I have no idea if this will work in cygwin, you may need to install some more things.
Code:
cd /path/to/source
DATE=$(date +%m%d%Y)

echo *.txt | sed 's/.\.txt//' | sort -u |
while read PREFIX
do
    N=1
    for X in "${PREFIX}"*".txt"
    do
            VAL=$(printf "%02d" ${N})
            echo mv "${X}" /path/to/dest/"${PREFIX}_${DATE}_${VAL}.txt
            N=$((N+1))
    done
done

Remove the 'echo' once you're sure it does what you want.
 
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 change existing date to current date in a filename?

Suppose i have a list of files in a directory as mentioned below 1. Shankar_04152019_ny.txt 2. Gopi_shan_03122019_mi.txt 3. Siva_mourya_02242019_nd.txt .. . . . . 1000 . Jiva_surya_02282019_nd.txt query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Discussion started by: Shankar455
4 Replies

2. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

3. UNIX for Dummies Questions & Answers

Select text between current date and output to new txt file

Hi guys, brand new to this thread and very very new to UNIX...so go easy please! Anyway I have a file that looks like this: >>-------------------------------------------------------------------------- Date/Time/Eng. : 2012-06-22 / 00:26 / DS Reported problem : (SD) ... (5 Replies)
Discussion started by: martin0852
5 Replies

4. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

5. Shell Programming and Scripting

how to append current date to filename.tgz in perl

i would like to know how to append current date in a filename with .tgz extension. #!/usr/bin/perl my $date = `date + %Y%m%d`; system("sudo mv /tmp/nyucs01_config_backup.tgz /misc/nyucs01_config_backup_$date.tgz"); im getting this error message: sh: line 1: .tgz: command not found (7 Replies)
Discussion started by: linuxgeek
7 Replies

6. Shell Programming and Scripting

[PERL] Cannot stat or move filename - £££F3AERO££.txt

Scenario: Users drop files into a directory which is regularly polled by my PERL process. On detecting a file my process will move it from the poll dir to a working directory. A user created a file with a £ symbol in the filename and my process now fails. e.g £££F3AERO££.txt ... (1 Reply)
Discussion started by: thefal9
1 Replies

7. UNIX for Dummies Questions & Answers

shell scripts - create a filename with the date appended

I am looking to do something where if I created a file named backup,or whatever it would print a name like “backup_Apr_11_2011”. Thanks citizencro (1 Reply)
Discussion started by: citizencro
1 Replies

8. Shell Programming and Scripting

Move files based on date in filename

I know this gets covered quite a bit in the forum and I think there is enough there for me to figure out how to do what I am trying to do, I just don't think I would do it very efficiently so I am going to ask the question... I have database log files with date and time stamps in the file like ... (7 Replies)
Discussion started by: slatoms
7 Replies

9. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

10. UNIX for Dummies Questions & Answers

Append current date to filename

In C Shell programming I haven't successfully been able to append the date in the format mmddyyyy to a filename. I've tried the following: I can print out the date in the correct format: date +%x | sed ‘s/\///g I can create a variable with the filename: set newfile=changedfiles I can... (3 Replies)
Discussion started by: gigigi
3 Replies
Login or Register to Ask a Question
i-ls(1) 						      General Commands Manual							   i-ls(1)

NAME
i-ls - display file stat and checksum information for files SYNOPSIS
i-ls [-s] filename i-ls [-s] dirname Specify a filename for i-ls to examine, or specify a directory with dirname to examine all the files in the directory. -s Do not show/calculate checksums for all regular files. DESCRIPTION
The integrit system detects intrusion by detecting when trusted files have been altered. integrit records information about files in a database. i-ls allows the user to see that information for live files. The output syntax is the same as that of integrit. EXAMPLES
i-ls /tmp/foo.txt shows file stat attributes for the file, "/tmp/foo.txt". i-ls /tmp shows file stat attributes for all files in the directory, "/tmp". i-ls -s /tmp shows file stat attributes for all files in the directory, "/tmp", also including also checksums for all regular files. AUTHOR
Ed L Cashin <ecashin@users.sourceforge.net> See the integrit web site for up to date releases and information at http://integrit.sourceforge.net/ SEE ALSO
Integrit File Verification System Manual (info), lstat(2) Version 4.1 Jul 27, 2001 i-ls(1)