![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple file existence and checking file size | lathish | Shell Programming and Scripting | 2 | 06-29-2008 12:03 PM |
| Data File Processing Help | mavsman | UNIX for Dummies Questions & Answers | 5 | 03-27-2008 04:49 PM |
| Error checking a file from previous file size | stuck1 | Shell Programming and Scripting | 2 | 12-06-2007 08:39 AM |
| Have a shell script check for a file to exist before processing another file | heprox | Shell Programming and Scripting | 3 | 11-14-2006 03:26 AM |
| processing data in a flat file | wolkott | Shell Programming and Scripting | 4 | 01-27-2003 01:57 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Checking for a control file before processing a data file
Hi All,
I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data file, then Sample_20081001.ctl will be the control file. Now if the ctl file exists, then only i have to move that particular txt file into another directory. Others i should not move. And the .txt and .ctl files will be multiple. This is my requirement. Can anybody please give a solution? Thank you very much. |
|
||||
|
Dear Dennis,
Thank you for a prompt response.... Can you tell me wht x%% refers... As i am new to shell scripting, i am not able to understand the code snippet you have given... Can you please explain how this works... So that i can tailor it according to my requirement.... Thank you... |
|
||||
|
Quote:
Code:
#look for all the .ctl files
for each in $(ls -1 *.ctl)
do
#extract the filename without ctl extention and search for {filename}.txt
# if it is there, move to a different folder
[[ -f "${each%%.ctl}.txt" ]] && { mv ${x%%.ctl}.txt ./new_folder/ }
done
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|