Login or Register to Ask a Question and Join Our Community

Script to move files based on Pattern don't work

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to move files based on Pattern don't work
# 1  
Old 10-20-2008
Script to move files based on Pattern don't work

Hi people,

i need you help on this if you can.

I have a script that does the move command when it searches for a that doesn't match the pattern. This Pattern is on a list.

When it run's and doesn´t found no files but it haves 2 more folders it moves the folders too.

stamp=`/usr/bin/date +"%Y%m%d%H%M"`

####################################### **** FUNCOES ***



for i in $GETF
teste1=`echo $i | awk -F ';' '{print $1}'`
echo $teste1 >> $LOGS/Check_files_1_$stamp.log
teste2=`echo $i | awk -F ';' '{print $2}'`
echo $teste2 >> $LOGS/Check_files_1_$stamp.log
teste3=`echo $i | awk -F ';' '{print $3}'`
echo $teste3 >> $LOGS/Check_files_1_$stamp.log
cd $WORKDIR/$teste2 >> $LOGS/Check_files_1_$stamp.log
basico=`ls -I "$teste3" | grep -v Historico`
echo $basico >> $LOGS/Check_files_1_$stamp.log
for j in `echo $basico`
cp $WORKDIR/$teste2/$j $WORKDIR/ERROR_FILES >> $LOGS/Check_files_1_$stamp.log
sleep 5
echo cd $WORKDIR >> $LOGS/Check_files_1_$stamp.log


The list :



For example, the folder NEO_ESPANHA all files that doesn't match the pattern " AS_????????.xls" but me moved to a folder of ERROR_FILES. What appens is it move the subfolders too when i do a ( ls -I "AS_????????.xls" ).

I'm doing this on the Cygwin tool.

Can someone help me ?


# 2  
Old 10-22-2008
I think you need to have no space between -I and the pattern to ignore, e.g.:

basico=`ls -I"$teste3" | grep -v Historico`

You can make sure it is a file before copying it by doing something like this:

[[ -f $WORKDIR/$teste2/$j ]] && cp $WORKDIR/$teste2/$j $WORKDIR/ERROR_FILES >> $LOGS/Check_files_1_$stamp.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to append multiple text files into one file based on pattern present in filaname

Hi All-I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames? AAAL_555A_ORANGE1_F190404.TXT AAAL_555A_ORANGE2_F190404.TXT AAAL_555A_ORANGE3_F190404.TXT... (6 Replies)
Discussion started by: Shankar455
6 Replies

2. Shell Programming and Scripting

Move files with a certain suffix based on how many files are in another folder

Hello, First time poster. I am looking for a way to script or program the process of moving files from one folder to another, automatically, based on the count of files in the destination folder. I was thinking a shell script would work, but am open to the suggestions of the experts... (6 Replies)
Discussion started by: comtech
6 Replies

3. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

4. Shell Programming and Scripting

Move directories in script.sh doesn't work

Dear All, I would like move some directories in another location. Basically, my ls -lis drwxr-xr-x 3 XXXXXXXXXXXXXXXXXXXX 4096 Feb 24 02:18 data.N701_N502.ABCDE -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX 185865797 Feb 23 11:27 data.N701_N502.ABCDE_file1 -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

5. UNIX for Dummies Questions & Answers

Need script to move files based on month

Hi , I need a script which moves files based on month. Example : Apr 29 03:16 log4.txt Apr 29 03:16 log5.txt May 4 09:17 log1.txt May 4 09:17 log2.txt Move Apr files into Apr2015(Folder) Move May files into May2015(Folder). This is urgent requirement , if you can help me... (5 Replies)
Discussion started by: rockingvj
5 Replies

6. UNIX for Dummies Questions & Answers

HELP Script don't work selecting lowest value!!!

Hy again guys, Last week i resolve a question here but now i need your help again :rolleyes: I have about 3000 files that i need to choose based on the lowest value, so i make temp files like this: The files can have lines from 1-10 but only 2 columns, the point is to grep the name os the... (2 Replies)
Discussion started by: MetaBolic0
2 Replies

7. Shell Programming and Scripting

Need script to move files based on name

Hi folks, I'm new here and appreciate greatly any help. I have a bunch of files that need be moved and renamed. Fortunately, they are all in sequence... Present filename and path: /.catalog1/t76038_842-01 Move to: /.catalog1/76038-01 So, we need to drop the... (8 Replies)
Discussion started by: axslinger
8 Replies

8. Solaris

I don`t understand how It work (about startup script)?

Hi all. The startup script in /usr/local/bin. After user login the script run an application. Iwould in the same way run the another application. How to make It similar? Where I must to look? Regards. (3 Replies)
Discussion started by: wolfgang
3 Replies

9. Shell Programming and Scripting

Unix Script To Move Files Based On Grep

I am looking for advice on how to write a script that will rename and/or move files to a different directory based upon the results of a grep. Let's say I have ten files in a directory. Some of them - not all - contain the text 'HELLO'. I would like to be able to grep the files for that text,... (3 Replies)
Discussion started by: rjhjr64
3 Replies

10. Shell Programming and Scripting

find options don't work in script

Hi, I'm trying to write a bash script to find some files. However it seems that the find command is not behaving the same way when the script is executed as it does when executed from the command line: Script extract: #!/bin/bash ... NEW="/usr/bin/find current/applications/ -name '*jar'... (3 Replies)
Discussion started by: mattd
3 Replies
Login or Register to Ask a Question

Featured Tech Videos