Copying files with a specific pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying files with a specific pattern
# 15  
Old 05-22-2014
only one file is qualifying this as other doesn't have code instead, they have zone / extract
Code:
for i in cost revenue benefit profit
do
cp ${SOURCE}/aaa_bbb_ccc_ddd_${i}_code_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*.gz ${$DESTN_DIR}
done

---------- Post updated at 03:09 AM ---------- Previous update was at 03:07 AM ----------

or if you have a specific data to search for
Code:
DT=$(date +%Y%m%d)
for i in cost revenue benefit profit
do
cp ${SOURCE}/aaa_bbb_ccc_ddd_${i}_code_${DT}*.gz ${$DESTN_DIR}
done

# 16  
Old 05-22-2014
Thanks a lot @SriniShoo. It's copying the required files to the destination folder now. Smilie

---------- Post updated at 05:19 AM ---------- Previous update was at 03:41 AM ----------

I just stumbled upon another problem actually. When the same is being used within sftp, it doesn't seem to work with either of these options:

Code:
cd /temp
for i in cost revenue benefit profit
do   
   # using SFTP method
   sftp $REMOTUSR <<EOF>>$OUT 2>&1
   put aaa_bbb_ccc_ddd_${i}_code_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].csv.gz $REMOTDIR
   quit
EOF

or

Code:
cd $SOURCE
if [ ! -d tmp ]; then
mkdir tmp
fi

cd /temp
for i in cost revenue benefit profit
do
   cp aaa_bbb_ccc_ddd_${i}_code_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].csv.gz $SOURCE/tmp
   cd $SOURCE/tmp
   #using SFTP method
   sftp $REMOTUSR <<EOF>>$OUT 2>&1
   cd $REMOTDIR
   get *
   quit
EOF

# 17  
Old 05-22-2014
How about rsync (using regex already mentioned in posts)
Code:
rsync -av --exclude="*loss_zone*" --exclude="*username*" SOURCEDIR/ user@remotehost:DESTDIR/

# 18  
Old 05-23-2014
@Srini,

Copying the files to the remote server from local is working with the option you had suggested but once on the server, am not able to move the files from one location to another. The code is something like this:

Code:
    for i in a b c d
    do
    sftp $REMUSR <<EOM>>$OUT 2>&1
    rename $SOURDIR/sample_${i}_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz $REMDIR
    quit
    EOM
    :
    :
    done

but i get the message

Code:
    Couldn't rename file "/source/sample_a_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz" to       "/destin/": No such file or directory

though this file exists under the /source directory which i verified:

Code:
    ls -l sample_a_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz
    -rw-r--r--  1 prd admin 112 May 23 09:16 sample_a_20140330.gz

Am not able to get my head around why this could be Smilie

---------- Post updated at 03:36 AM ---------- Previous update was at 01:13 AM ----------

The below is not working either:

Code:
for i in a b c d
do
fname=`ls sample_${i}_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz`
sftp $REMUSR <<EOM>>$OUT 2>&1
rename $SOURDIR/$fname $REMDIR/
quit
EOM
:
:
done


Last edited by Franklin52; 05-23-2014 at 05:38 AM.. Reason: fixed code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying specific file types to specific folders

I am trying to write a script that cycles through a folder containing many folders and when inside each one it's supposed to copy all the .fna.gz files to a folder elsewhere if the file and the respective folder have the same name. for fldr in /home/playground/genomes/* ; do find .... (8 Replies)
Discussion started by: Mr_Keystrokes
8 Replies

2. Shell Programming and Scripting

Bash: copying lines with specific character to files with same name as copied line.

I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines... (2 Replies)
Discussion started by: Allie_gastrator
2 Replies

3. Shell Programming and Scripting

Copying files based on a pattern

Hi All, I need to find and list the last 5 days files in that exact name with "MIM" and copy to another directory. please help me in this there is around 30000 files Thanks Murali (7 Replies)
Discussion started by: 969murali@gmail
7 Replies

4. Shell Programming and Scripting

list files with a specific pattern

How can I list files with the following specific criteria? I am trying this $> ls *.log or $>ls *.log? --> but it only gives me fsaffa.log1, rwerw.log2. How can I get all three files with a simple selection criteria ? (5 Replies)
Discussion started by: kchinnam
5 Replies

5. Shell Programming and Scripting

copying columns with headers' specific pattern

Hi friends, I have data in tab separated file with headers like this : *sml1 *sml3 *smln7 smfk9 smllf56... Which shell command I should use if i want to extract entire columns that have header names beginning with "*" ? i want to copy these columns into another file. Thanks, (14 Replies)
Discussion started by: jacks
14 Replies

6. Shell Programming and Scripting

Copying specific files from one dir to another

Hi Folks, I have one curious case. There are list of following files placed in one directory such as... And updated each month. files.JAN09.csv files.FEB09.csv files.MAR09.csv ..... Now, I need to move a specific files; i.e, For this month, I need to move only OCT09, NOV09, DEC09,... (1 Reply)
Discussion started by: Jerald Nathan
1 Replies

7. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

8. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

9. UNIX for Dummies Questions & Answers

Copying specific files

I wanted to see if some one could confirm the proper command and format for copying specific files i.e., ones that contain certain character string in the file name. I would like to copy all files that contain a numeric sequence in the file name i.e., "922371". Files are compressed - *.gz. Would... (3 Replies)
Discussion started by: faaron3
3 Replies

10. Shell Programming and Scripting

Finding a specific pattern from thousands of files ????

Hi All, I want to find a specific pattern from approximately 400000 files on solaris platform. Its very heavy for me to grep that pattern to each file individually. Can anybody suggest me some way to search for specific pattern (alpha numeric) from these forty thousand files. Please note that... (6 Replies)
Discussion started by: aarora_98
6 Replies
Login or Register to Ask a Question