Code to remove files when corresponding file doesnt exist isnt working.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Code to remove files when corresponding file doesnt exist isnt working.
# 1  
Old 01-15-2012
Code to remove files when corresponding file doesnt exist isnt working.

I am trying to add some code to the begging of a script so that it will remove all the .transcript files, when their is no coressponding .wav file. But it doesnt work.
This is the code I have added:
PHP Code:
for transcriptfile in `$voicemaildir/*.transcript`; do
wavfile=`echo $transcriptfile | cut -d'.' -f1`.wav

# If the transcript file exists but the wav file does not, remove the transcript.
if [[ -f $transcriptfile && ! -f $wavfile ]]; then
rm 
-f $transcriptfile
fi
done 
Here is the entire script:

PHP Code:
!/bin/sh

voicemaildir
=/var/spool/asterisk/voicemail/$1/$2/INBOX/

echo `
date':' $voicemaildir >> /var/log/voicemail-notify.log

for transcriptfile in `$voicemaildir/*.transcript`; do
wavfile=`echo $transcriptfile | cut -d'.' -f1`.wav

# If the transcript file exists but the wav file does not, remove the transcript.
if [[ -f $transcriptfile && ! -f $wavfile ]]; then
rm 
-f $transcriptfile
fi
done

for audiofile in $voicemaildir/*.wav; do
   transcriptfile=${audiofile/wav/transcript}
   flacfile=${audiofile%.wav}.flac
   # For each message.wav we check if message.transcript
   # exists
   if [ ! -f $transcriptfile ]; then
      # If not, we create it
      flac --best --sample-rate=8000 "$audiofile" -o "$flacfile"
      speech-recog-cli.pl $flacfile  | head -2 | tail -1 | cut -f 2 -d ":"  > $transcriptfile

      # Now we can do whatever we want with the new transcription
      echo `cat $transcriptfile`
  
 fi
done 
Thanks
# 2  
Old 01-15-2012
You Don't want backquotes in the for command line. Try something like this:

Code:
for transcriptfile in *.transcript
do
   wavfile=${transcriptfile%.*}.wav
   [ -f "$transcriptfile" -a ! -f "$wavfile" ] && rm -f "$transcriptfile"
done

# 3  
Old 01-16-2012
hi.. here is another solution..

Code:
for file in `ls -1 *.transcript`
do
 name=`basename $file ".transcript"`".wav"
 if [ -f ${file} -a ! -f ${name} ]
 then
  rm -f $file
 fi
done

Regards,
A!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -w ip address from a file isnt working need help

I have a file "file1" that contains several ip address , and the "file2" contains several records , each line in file2 contains somewhere the ip address that i am searching in the file1 I use the unix command grep -w for i in `cat file1` do grep -w "$i" file2 >> file3 done ... (9 Replies)
Discussion started by: knijjar
9 Replies

2. Shell Programming and Scripting

File exist for multiple files

Hi, I am unable to achieve the file exist conditions if there are multiple files same similar name for e.g. in a $Direct i am having files like aus.txt aus.txt_pr aus.txt_2012 i need to put a file exist condition like which is not working then echo "File present" but the... (9 Replies)
Discussion started by: rohit_shinez
9 Replies

3. Shell Programming and Scripting

Remove lines from one file that exist in another file

Hello Everyone, I'm currently have a requirement where I've generated a list of files with specific attributes and I need to know what lines are similar between the two files. For example: -File 1- line1 line2 line3 -File 2- line1 line2 line4 line5 -Desires Output- line1 line2... (5 Replies)
Discussion started by: omnivir
5 Replies

4. UNIX for Dummies Questions & Answers

Removing a user that doesnt exist from a group

Hi there, normally if I want to remove a user tht I have added to a specific group, i would do the following this is what my group2 looks like # grep group2 /etc/group group2:x:7777:user2,user1,user4 user1 has been defined in a few groups # id -nG user1 group1 group2 group3 So... (3 Replies)
Discussion started by: rethink
3 Replies

5. UNIX for Dummies Questions & Answers

Cleanup job to remove old files suddenly not working

Hi I have a job that has been running for a while with the following statement to cleanup a directory: find /dbmgtu01/app/myplace/log ! \( -name "dc*" -o -name "sc*" -o -name "ms*" \) -type f -mtime +30 -print -exec rm {} \ ; The directory was recently changed to a mount point, with a symbolic... (2 Replies)
Discussion started by: CAGIRL
2 Replies

6. Shell Programming and Scripting

Check file and if it doesnt exist , exit script

Hi, Another problem, here is my code #!/bin/sh dir='/opt/apps/script/CSV' datadir='/opt/apps/script/data' while : ; do ls -1rt $dir/*.csv > /dev/null 2>&1 if ;then cp $datadir/weekly.txt $dir/weekly.csv else exit 0 fi done (10 Replies)
Discussion started by: tententen
10 Replies

7. Shell Programming and Scripting

If doc file exist remove

I need help running a script. I have the script looking into a folder and converting .doc files to .odt. The script works fine except that I want it to only run when .doc files are present. If I can do this then I can put .xls files and .ppt files in the folder and convert them when they are... (2 Replies)
Discussion started by: handband2
2 Replies

8. Shell Programming and Scripting

why isnt cron working?

I am using Ubuntu linux desktop, and I am trying to schedule a sheel script to run every 10minutes. These are the steps I have taken: crontab -e added and saved this line to the file # m h dom mon dow command */1 * * * * /home/enzo/Desktop/dlrecentuse restarted cron: sudo... (5 Replies)
Discussion started by: daydreamer
5 Replies

9. Red Hat

trying to use arp command... it doesnt exist

im trying to get an ARP readout using the command 'arp -a'... but the command doesnt exist in Fedora Core 6 - IPv6.... is there an equivalent command? (4 Replies)
Discussion started by: HMSS013
4 Replies

10. Shell Programming and Scripting

Why passwd isnt working in shell scripts?

I had to write a script to change my login password, and the script wasnt working fine. When I searched through the previous postings in this forum, I got the solution (using 'expect' tool). But I would like to know why passwd command isnt working in scripts? (1 Reply)
Discussion started by: Deepa
1 Replies
Login or Register to Ask a Question