Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Rename files in a directory and move them Post 302853323 by andymay on Friday 13th of September 2013 04:59:22 PM
Old 09-13-2013
Rename files in a directory and move them

I have a directory e2e_ms_xfer/cent01
this contains the multiple files some of which will be named below with unique date time stamps
e2e_ms_edd_nom_CCYYMMDD_HHMM.csv
What I want to do is in a loop
1) Get the oldest file
2) Rename
3) Move it up one level from e2e_ms_xfer/cent01 to /e2e_ms_xfer
3) Process it
4) Move it down 2 levels to e2e_ms_xfer/cent01/done
4) Exit loop

This is what I have below but it does not do step 2 it says it cannot find files of that name although I have put 5 unique
e2e_ms_edd_nom_CCYYMMDD_HHMM.csv in the directory.

Code:
#
#
# Control the Unix processing cycle for uploading
# M+S Nomiated Delivery Days into the E2E database.
#
# 1.0  AM  13/09/2013  Initial Version
#
set +xv
 
# Execute the .profile (coz cron doesn't)
. ~/.profile
 
# Library functions
. $( dirname $0 )/common_functions.ksh
 
THIS=$( basename $0 )
 
fn_banner "Process M+S Nominated Delivery Days files"
 
echo "Starting: $(date)"
fn_writeTrace "starting"
 
 
# Local variables
bookmark="10"
TODAY=$(date "+%Y%m%d")
D_EXTTAB=/e2e_ms_xfer
MASK=e2e_ms_edd_nom*
D_WORK=$XFMSC
D_DONE=$XFMSZ
JOBNAME=$( echo $THIS | cut -f1 -d. )
 
 
fileCount=0
 
# Oracle
bookmark="20"
fn_oraenv
 
# Good to go
bookmark="30"
runControl=1
 
 while [ $runControl -eq 1 ]
 do
   cd $D_WORK
 
 
     # Are there any files?
    bookmark="35"
    fileFound=0
    ls -1 $MASK > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        # Oldest file
        bookmark="37"
        fileName=$( ls -1 $MASK | head -n 1 )
        mv filename e2e_ms_edd_nom.csv
 
        let fileCount=fileCount+1
        fileFound=1
 
       # Move the file to where the ext.tables expect
        bookmark="40"
        mv $XFMSC/e2e_ms_edd_nom.csv $XFMS
 
        # Invoke the Oracle process to upload the data
        #
        bookmark="50"
        fn_oraenv
        sqlplus $OCS @$SQL/exec_pull_nom_del_date.sql
 
        # Move the file to 'done'
        #
        bookmark="60"
        mv $XFMS/e2e_ms_edd_nom.csv $XFMSZ
       
     fi # file found
 
 
    fn_setHeartbeat $JOBNAME
 
done # while
 
# All done - Cleanup and exit
#
bookmark="70"
fn_cleanup
echo "Complete: $(date)"
fn_writeTrace "complete"
 
exit 0


Last edited by Scrutinizer; 09-13-2013 at 07:54 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files and rename ??

1. If I have a file-yyyymmdd.dat in a directory DATA1, then how do I move this file to directory DATA2 and the file name change to file-yyyymmdd.dat.currenttime I can manual do this $mv fileA-yyyymmdd.dat ./DATA2/fileA-yyyymmdd.dat.`date +%Y%m%d%H%M%S` but how do I move all of the files in... (1 Reply)
Discussion started by: sabercats
1 Replies

2. Shell Programming and Scripting

Move and rename files in seq. with padded digits

Greetings, I am new to scripting, but find if I can see the code working for a given problem, then I can eventually figure it out. (9 Replies)
Discussion started by: rocinante
9 Replies

3. Shell Programming and Scripting

Find, Append, Move & Rename Multiple Files

Using a bash script, I need to find all files in a folder "except" the newest file. Then I need to insert the contents of one text file into all the files found. This text needs to be placed at the beginning of each file and needs a blank line between it and the current contents of the file. Then I... (5 Replies)
Discussion started by: Trapper
5 Replies

4. UNIX for Dummies Questions & Answers

Using Rename to move files

I am connecting to a remote server (Unix) and doing a ftp dowmload of files. The script (VB script) works fine except for not being able to move the downloaded files on the remote server to another folder. I need to move all files with an .asc extesnion from folder "tovecellio_edi" to folder... (1 Reply)
Discussion started by: snufse
1 Replies

5. Shell Programming and Scripting

Rename/Move files and schedule the script

Hello, I'm new in the forum and in UNIX scripting, what I need is to write a simple batch script that renames or move the files back & forth from one directory to another, and then schedule the script to run on the server when the scheduled down time is, which is on Thursdays at 8pm and during... (5 Replies)
Discussion started by: dannyghost
5 Replies

6. Shell Programming and Scripting

Need to move and rename a list of files

Hi, I need to do something easy but I can't seem to figure out how to do this. Let's say I have 6 files in the directory below: /ebsbeta_f/flash/EBSUATQB/onlinelog o1_mf_6_55klt7nr_.log o1_mf_3_55klskj4_.log o1_mf_4_55klsrl1_.log o1_mf_5_55klt09p_.log o1_mf_2_55klv1ts_.log... (10 Replies)
Discussion started by: exm
10 Replies

7. Shell Programming and Scripting

Windows Power Shell - rename files and move

hi people; i want to make a file/folder operation as follows. - i have 41 folders in Windows and each of them have same-named files (~200 files each) inside. - i want to stack these files together in a folder but Windows is asking to "overwrite" (as usual) since the file names are the same.... (2 Replies)
Discussion started by: gc_sw
2 Replies

8. Shell Programming and Scripting

Replace string, grab files, rename and move

Hello there! I'm having a lot of trouble writing a script. The script is supposed to: 1) Find all files with the name "Object.mtl" within each folder in the directory: /Users/username/Desktop/convert/Objects 2) Search and replace the string ".bmp" with ".tif" (without the quotations) 3)... (1 Reply)
Discussion started by: Blue Solo
1 Replies

9. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

10. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies
RENAME(2)							System Calls Manual							 RENAME(2)

NAME
rename - change the name of a file SYNOPSIS
#include <stdio.h> int rename(const char *from, const char *to) DESCRIPTION
Rename causes the link named from to be renamed as to. If to exists, then it is first removed. Both from and to must be of the same type (that is, both directories or both non-directories), and must reside on the same file system. Rename guarantees that an instance of to will always exist, even if the system should crash in the middle of the operation. If the final component of from is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. RETURN VALUE
A 0 value is returned if the operation succeeds, otherwise rename returns -1 and the global variable errno indicates the reason for the failure. ERRORS
Rename will fail and neither of the argument files will be affected if any of the following are true: [ENAMETOOLONG] A path name exceeds PATH_MAX characters. [ENOENT] A component of the from path does not exist, or a path prefix of to does not exist. [EACCES] A component of either path prefix denies search permission. [EACCES] The requested link requires writing in a directory with a mode that denies write permission. [EPERM] The directory containing from is marked sticky, and neither the containing directory nor from are owned by the effective user ID. [EPERM] The to file exists, the directory containing to is marked sticky, and neither the containing directory nor to are owned by the effective user ID. [ELOOP] Too many symbolic links were encountered in translating either pathname. (Minix-vmd) [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] From is a directory, but to is not a directory. [EISDIR] To is a directory, but from is not a directory. [EXDEV] The link named by to and the file named by from are on different logical devices (file systems). [ENOSPC] The directory in which the entry for the new name is being placed cannot be extended because there is no space left on the file system containing the directory. [EIO] An I/O error occurred while making or updating a directory entry. [EROFS] The requested link requires writing in a directory on a read-only file system. [EFAULT] Path points outside the process's allocated address space. [EINVAL] From is a parent directory of to, or an attempt is made to rename ``.'' or ``..''. [ENOTEMPTY] To is a directory and is not empty. SEE ALSO
open(2) 4.2 Berkeley Distribution May 22, 1986 RENAME(2)
All times are GMT -4. The time now is 03:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy