Sponsored Content
Top Forums Shell Programming and Scripting Move files based on date in filename Post 302432610 by dr.house on Friday 25th of June 2010 01:17:20 PM
Old 06-25-2010
How about ...

Code:
#!/bin/bash

for FILE in $( ls db2diag*.log )
do
  FOLDER=$( echo $FILE | awk -F '-' '{print $2"_"$3}' )
  if [ ! -d $FOLDER ]
  then
    mkdir -v $FOLDER
  fi
  mv -v $FILE $FOLDER
done

exit 0
# finis

Code:
[house@leonov] ls db*
db2diag-2010-04-09-06.04.01.log  
db2diag-2010-04-10-06.04.01.log  
db2diag-2010-05-10-06.04.01.log
[house@leonov] bash code.bash
mkdir: created directory `2010_04'
`db2diag-2010-04-09-06.04.01.log' -> `2010_04/db2diag-2010-04-09-06.04.01.log'
`db2diag-2010-04-10-06.04.01.log' -> `2010_04/db2diag-2010-04-10-06.04.01.log'
mkdir: created directory `2010_05'
`db2diag-2010-05-10-06.04.01.log' -> `2010_05/db2diag-2010-05-10-06.04.01.log'
[house@leonov] lr 2010*
2010_04:
db2diag-2010-04-09-06.04.01.log
db2diag-2010-04-10-06.04.01.log
2010_05:
db2diag-2010-05-10-06.04.01.log

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier. ... (7 Replies)
Discussion started by: italia5
7 Replies

2. UNIX for Dummies Questions & Answers

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (2 Replies)
Discussion started by: Sriranga
2 Replies

3. Shell Programming and Scripting

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (4 Replies)
Discussion started by: Sriranga
4 Replies

4. Shell Programming and Scripting

Move file based on filename

Hi All I need a script to manipulate files based on a filename: example filename: 66600_042706.pdf the script will create a directory 66000 only if this directory is not existing. If that directory is existing it will just move the file to 66000/666000_042706.pdf in addition, i want to... (4 Replies)
Discussion started by: aemestech
4 Replies

5. Shell Programming and Scripting

Get the oldest date based on date in the filename

I am using ksh93 on Solaris. Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this: 20110501_1.dat 20110501_2.dat 20110501_3.dat... (2 Replies)
Discussion started by: gary_w
2 Replies

6. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ‘AB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

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

8. UNIX for Dummies Questions & Answers

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... (7 Replies)
Discussion started by: johannd
7 Replies

9. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies
BLAZE-LOG(1)						    BlazeBlogger Documentation						      BLAZE-LOG(1)

NAME
blaze-log - displays the BlazeBlogger repository log SYNOPSIS
blaze-log [-cqrsCV] [-b directory] [-n number] blaze-log -h|-v DESCRIPTION
blaze-log displays the content of the BlazeBlogger repository log. OPTIONS
-b directory, --blogdir directory Allows you to specify a directory in which the BlazeBlogger repository is placed. The default option is a current working directory. -n number, --number number Allows you to specify a number of log entries to be listed. -s, --short Tells blaze-log to display each log entry on a single line. -r, --reverse Tells blaze-log to display log entries in reverse order. -c, --color Enables colored output. When supplied, this option overrides the relevant configuration option. -C, --no-color Disables colored output. When supplied, this option overrides the relevant configuration option. -q, --quiet Disables displaying of unnecessary messages. -V, --verbose Enables displaying of all messages. This is the default option. -h, --help Displays usage information and exits. -v, --version Displays version information and exits. FILES
.blaze/log A file containing the repository log. EXAMPLE USAGE
List the whole repository history: ~]$ blaze-log Date: Sun Jul 25 16:48:22 2010 Edited the page with ID 5. Date: Tue Jul 6 18:54:59 2010 Edited the page with ID 5. etc. List the whole repository history in reverse order: ~]$ blaze-log -r Date: Tue Feb 10 00:40:16 2009 Created/recovered a BlazeBlogger repository. Date: Tue Feb 10 01:06:44 2009 Added the page with ID 1. etc. Display the very first log entry on a single line: ~]$ blaze-log -rs -n 1 Tue Feb 10 00:40:16 2009 - Created/recovered a BlazeBlogger repository. SEE ALSO
blaze-init(1), blaze-config(1) BUGS
To report a bug or to send a patch, please, add a new issue to the bug tracker at <http://code.google.com/p/blazeblogger/issues/>, or visit the discussion group at <http://groups.google.com/group/blazeblogger/>. COPYRIGHT
Copyright (C) 2009-2011 Jaromir Hradilek This program is free software; see the source for copying conditions. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Version 1.2.0 2012-03-05 BLAZE-LOG(1)
All times are GMT -4. The time now is 06:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy