Checking for a control file before processing a data file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for a control file before processing a data file
# 1  
Old 09-01-2008
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  
Old 09-01-2008
Try :

Code:
for each in $(ls -1 *.ctl)
do
[[ -f "${x%%.ctl}.txt" ]] && { mv ${x%%.ctl}.txt ./new_folder/ }
done

# 3  
Old 09-01-2008
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  
Old 09-01-2008
Quote:
Originally Posted by purna.cherukuri
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  
Old 09-01-2008
Thanks Dennis... It works for me fine...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

/tmp/man18809436: Invalid file system control data detected

/tmp/man18809436: Invalid file system control data detected Help me what do I do? Если знаете русскии, пишите на нем. (2 Replies)
Discussion started by: islily
2 Replies

2. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

3. Shell Programming and Scripting

Checking data in csv file after headers

I had a requirement to check if data exists after headers (typically row 2 & so on) in csv file. please help how we can check through shellscript in linux. Thank you !! (1 Reply)
Discussion started by: chandu123
1 Replies

4. Shell Programming and Scripting

awk processing of variable number of fields data file

Hy! I need to post-process some data files which have variable (and periodic) number of fields. For example, I need to square (data -> data*data) the folowing data file: -5.34281E-28 -3.69822E-29 8.19128E-29 9.55444E-29 8.16494E-29 6.23125E-29 4.42106E-29 2.94592E-29 1.84841E-29 ... (5 Replies)
Discussion started by: radudownload
5 Replies

5. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

6. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

7. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

8. UNIX for Dummies Questions & Answers

Checking Data in File

Using If_ELSE, how do check a particular piece of data in a file. My data file has three columns and say I want to check the data in the 2nd column. I want to do a comparsion against a another piece of data using IF_ELSE. How do I get that data in file to check? (1 Reply)
Discussion started by: razer212
1 Replies

9. UNIX for Dummies Questions & Answers

Data File Processing Help

I need to read contents of directory and create a list of data files that match a certain pattern and process by renaming it and calling a existing .ksh script then archiving off to file another directory. Any suggestions or samples u could point me to on using .ksh perl or other to process... (5 Replies)
Discussion started by: mavsman
5 Replies

10. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies
Login or Register to Ask a Question