File extension search and copy


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users File extension search and copy
# 8  
Old 03-26-2008
If they are all in the same folder then what's wrong with

Code:
cp folder/*.txt folder/*.csv otherlocation/

As far as that hideous find command line is concerned, is it really not more elegant to say

Code:
find . \( -name "*.csv" -o -name "*.txt" \) ...

(You have to escape the parens from the shell, something the find manual page doesn't typically stress enough.)
# 9  
Old 03-26-2008
Thanks all. I had one lat thing i need to schedule it through cron to run every first wednesday of the month.

I know crontab -e will take me to cron and editing it in Vi editor:

50 23 * * 0-5 /usr/sandeep/TestAutomate.sh


how can we get this thing run every first wednesday of the month?

Thanks,
Sandeep
# 10  
Old 03-26-2008
Add the following lines at the beginning of your script:

eval "date '+MM=%m'"
[ -f $HOME/TestAutomate.M$MM ] && exit
rm -f $HOME/TestAutomate.M??; touch $HOME/TestAutomate.M$MM

and schedule it to run on Wednesdays ONLY!!
# 11  
Old 03-26-2008
can you please explain this a bit? Will be helpfull

Thanks,
Sandeep
# 12  
Old 03-26-2008
Tthe traditional solution would be a self-scheduling at job. Then you can use arbitrary commands to specify the scheduling.

Code:
#!/bin/sh
: ... commands
when=`date -d "4 weeks"`
# code to figure out when to wait 5 weeks left as an exercise
echo "$0" "$@" | at $when

# 13  
Old 03-26-2008
Unilover's solution relies on finding a file with this month's month number, and not doing the copying if it already exists. An alternative would be to compare the day number to 7, and only run if it is less. (Not having any external state would seem to me like an advantage.)
# 14  
Old 03-26-2008
The first line saves the two-digit Current-Month number in the MM variable (e.g. MM=03 for March).

The second line checks to see if there is a file named AutoTester.M$MM (e.g. AutoTester.M03) in the user's Home-Directory, exits the script. So, for all subsequent Wednezdays (i.e. the second, third, ... ) in the month, it would exit without doing anything.

The third line, which will only be reached and executed when there is NO AutoTester.M$MM file (i.e. THE FIRST WEDNEZDAY OF EACH MONTH), first removes all previous such files (for previous months) and then creates that file for the CURRENT MONTH (which will cause the second line to sense it and exit for all subsequent executions on other Wednezdays) and then continues to the rest of the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Search the pattern and copy in to the file

my qn is i have one file hex.txt.it contains some junk data and some hexa valueslike hex.txt sdfjhjkh 0x1233jkfhgjfhgajk;gha 0xacdd jkgahfjkgha;sjghajklgha;gh aghfjkgh;a 0xccc jhfjkhsd ox23cd 0x456 jkhdfjhjkafh like this now iwant a script like to separate the hex values and paste into the... (12 Replies)
Discussion started by: siva.hardwork
12 Replies

3. Shell Programming and Scripting

search a word and copy the file

Hi need help with a script or command My requirement is - I need to do a "ls -ltr tcserver*.syslog" files in /tmp, direct the output to a file ls -ltr tcserv*.syslog | grep "Jan 31" | awk '{printf "\n" $9}' > jandat.logs -Then open each file in above list and search for string/word,... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

5. Shell Programming and Scripting

search for a file extension

hi all, i'm new to shell scripting, i need help from u guys to do my task now.. i just need to check a file extension existence in a directory, and if it exists then i have to continue my processing. pls give me the command to check the extension of the files (6 Replies)
Discussion started by: divak
6 Replies

6. Shell Programming and Scripting

Search and copy to a new file-Help

Hi All, server16.na.in.com UNKNOWN ftpuser "CWD" dms-imrm/Delasco_Invoices_DayForward_Scan" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN ftpuser "CWD Private" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN... (7 Replies)
Discussion started by: Tuxidow
7 Replies

7. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

8. Shell Programming and Scripting

Recursicely search and rename file extension

Greetings to all!!:b: I have one root folder containing several other folders inside it. This tree structure is deep. And the files are of similar extension. I need to start at the top level and recursively search and rename all the files with say .a extension to .b . This is the code to... (7 Replies)
Discussion started by: riverside
7 Replies

9. Shell Programming and Scripting

Search for all the unique file extension

Greetings to All ... :b: I have one root folder containing different other folders within it. I need to get the list of all different types of file extensions residing in those folders. Could anyone help me providing some shell script? (1 Reply)
Discussion started by: riverside
1 Replies

10. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies
Login or Register to Ask a Question