The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 9 11-12-2008 09:12 PM
Recursicely search and rename file extension riverside Shell Programming and Scripting 7 04-11-2008 10:02 AM
Search for all the unique file extension riverside Shell Programming and Scripting 1 04-09-2008 04:47 PM
Search for strings & copy to new file amitrajvarma Shell Programming and Scripting 2 11-25-2007 11:51 PM
string search in folders with particular multiple file extension anikanch UNIX for Dummies Questions & Answers 2 10-28-2005 10:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished?

Thanks,
Sandeep
  #2 (permalink)  
Old 03-26-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
You can build a script around the command below and schedule it using some scheduler like cron.

Code:
find ./ -name "*.txt" -exec cp {} newfolder \;
  #3 (permalink)  
Old 03-26-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
Thanks. But need to to find both .txt and .csv files

Thanks,
Sandeep
  #4 (permalink)  
Old 03-26-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Play with patterns like the one below.

Code:
"*.[ct][sx][vt]"
This will work if you don't have any file with extensions
.cst
.cxv
.cxt
.tsv
.tst
.txv
  #5 (permalink)  
Old 03-26-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
Can you please help me put this together in the find command and alos explain this a bit.

It will helpful.

Thanks,
Sandeep
  #6 (permalink)  
Old 03-26-2008
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Code:
find ./ -name "*.[ct][sx][vt]" -exec cp {} newfolder \;
This command recursively finds from the current directory and subdirectories, files with names as per the below criteria.

After . the first character must be c or t (For .csv and .txt files)
After . the second character must be s or x (For .csv and .txt files)
After . the third character must be v or t (For .csv and .txt files)

Anyway, other combinations will also match (like .cxt) which I mentioned in my previous reply.

The exec in the above command copies all the found files (i.e, all .csv and .txt files we need) to the directory called newfolder.

Note: Better to have newfolder outside the current directory and not as a subdirectory in the present directory.
  #7 (permalink)  
Old 03-26-2008
ajn ajn is offline
Registered User
  
 

Join Date: Mar 2008
Location: USA
Posts: 1
You can use
if [ -e ./OrigLocation/*csv ] && [ -e ./OrigLocation/*txt ]; then
.....
.....
else
....
....
fi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0