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 > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-01-2008
purna.cherukuri purna.cherukuri is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
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.
  #2 (permalink)  
Old 09-01-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 558
Try :

Code:
for each in $(ls -1 *.ctl)
do
[[ -f "${x%%.ctl}.txt" ]] && { mv ${x%%.ctl}.txt ./new_folder/ }
done
  #3 (permalink)  
Old 09-01-2008
purna.cherukuri purna.cherukuri is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
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...
  #4 (permalink)  
Old 09-01-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 558
Quote:
Originally Posted by purna.cherukuri View Post
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...
Sorry, It was a typo, the modified script is

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
  #5 (permalink)  
Old 09-01-2008
purna.cherukuri purna.cherukuri is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 3
Thanks Dennis... It works for me fine...
Sponsored Links
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 04:51 AM.


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