If doc file exist remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If doc file exist remove
# 1  
Old 02-11-2009
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 detected.

This is what I currently have:
Code:
#! /bin/bash
for file in *.doc
    do
    if [ -e "*.doc" ]
        then
        mkdir ./ODT
        python /opt/DocumentConverter/DocumentConverter.py "${file}" "${file}".odt
        for i in *.odt; do j=`echo $i | sed 's/doc.odt/odt/g'`; mv "$i" ./ODT/"$j"; done
    fi   
done

Thanks!
# 2  
Old 02-11-2009
you don't need the 'if [ -e "*.doc" ]' (and the matching 'fi) - you will not go into the outter 'for' loop if there's nothing match against '*.doc'
# 3  
Old 02-11-2009
Quote:
Originally Posted by vgersh99
you don't need the 'if [ -e "*.doc" ]' (and the matching 'fi) - you will not go into the outter 'for' loop if there's nothing match against '*.doc'
Actually I need to identify what type of files exist within the folder or it makes necessary folders:
Code:
#! /bin/bash
##
soffice -headless -accept="socket,port=8100;urp;"
for file in *.doc
	do
	mkdir ./ODT
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./ODT/"${file}".odt
	for i in *.odt; do j=`echo $i | sed 's/doc.odt/odt/g'`; mv "$i" "$j"; done    
done

for file in *.xls
	do
	mkdir ./ODS
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./ODS/"${file}".ods
	for i in *.ods; do j=`echo $i | sed 's/xls.ods/ods/g'`; mv "$i" "$j"; done    
done

for file in *.ppt
	do
	mkdir ./ODP
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./ODP/"${file}".odp
	for i in *.odp; do j=`echo $i | sed 's/ppt.odp/odp/g'`; mv "$i" "$j"; done    
done

for file in *.odt
	do
	mkdir ./DOC
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./DOC/"${file}".doc
	for i in *.doc; do j=`echo $i | sed 's/odt.doc/doc/g'`; mv "$i" "$j"; done    
done

for file in *.ods
	do
	mkdir ./XLS
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./XLS/"${file}".xls
	for i in *.xls; do j=`echo $i | sed 's/ods.xls/xls/g'`; mv "$i" "$j"; done    
done

for file in *.odp
	do
	mkdir ./PPT
	python /opt/DocumentConverter/DocumentConverter.py "${file}" ./PPT/"${file}".ppt
	for i in *.ppt; do j=`echo $i | sed 's/odp.ppt/ppt/g'`; mv "$i" "$j"; done    
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove dashes if exist between positions 351-357 and then add - at the 357th position

I need to remove dash (i.e. -) if present from positions 351-357, and then add - (dash) at 357th position. For example in following first and 3rd record we got Before processing 1) 1st Record positions 351-357 = 0-12345 2) 3rd Record positions 351-357 = 00-4567 After processing:- 1) 1st... (7 Replies)
Discussion started by: lancesunny
7 Replies

2. 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

3. Shell Programming and Scripting

Remove words from file2 that don't exist in file1

Hi I have to list of words file1 and file2, I want to compare both lists and remove from file2 all the words that don't exist in file1. How can I do this? Many thanks (4 Replies)
Discussion started by: noliveira
4 Replies

4. Shell Programming and Scripting

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: for transcriptfile in `$voicemaildir/*.transcript`; do wavfile=`echo $transcriptfile | cut -d'.'... (2 Replies)
Discussion started by: ghurty
2 Replies

5. Web Development

Help with opening/viewing doc file via linux terminal

I am currently trying to open a .doc file in my workstation via terminal. This is my code: root@ojt:/home/ojt/Desktop# cat arts_life.doc and it gave me a bunch of unknown characters together with the contents of the doc file. What I actually want to happen is that it will open the... (4 Replies)
Discussion started by: chams
4 Replies

6. UNIX for Dummies Questions & Answers

Making backup to .doc file .... sh

im tring to make backup to the files end with "doc" extension but the code give me error ... what is the problem!!!! #! /bin/sh if then for name in `ls *.DOC` do kk= $(printf "%s_temp" $name) cp $name $kk done else echo "error" (9 Replies)
Discussion started by: maga6610
9 Replies

7. Shell Programming and Scripting

Search and remove digits (if exist) from end of the string

Hi Experts, Here is what I am trying to do. 1) say I have a file with below strings database1 database2 database3 data10gdb1 data10gdb2 databasewithoutdigit 2) I want to get the below output. (- if there is any digit at the end of the string, I need to remove it) (- Any... (3 Replies)
Discussion started by: shail_boy
3 Replies

8. Shell Programming and Scripting

Open and work on a .doc file with bash script

Hello there....unix users :) I hope you can help me with this: I need open a doc file or xls files and work this files whit a bash script. For example: Open a doc file and copy information from a txt file in this doc file or xls file. Is it possible? Sorry for my english...I'm chilean... (3 Replies)
Discussion started by: bobbasystem
3 Replies

9. UNIX for Dummies Questions & Answers

looking for patterns/tex in a .doc file

I'm learning Unix on my mac, and know that the grep command only works in text files. But what if I want to search for text/patters in a doc file, say? (I write my letters in NeoOffice and save them in .doc format). Is there a unix command that can do that? (4 Replies)
Discussion started by: Straitsfan
4 Replies

10. UNIX for Dummies Questions & Answers

deleteing .doc file

hi i ama dunmmies in Unix. I created a .doc file and copied it to unix via FTP as a ,doc file itself i want to delete that file , i tried with rm command it does not work file name is DDL's.doc plz help :confused: (2 Replies)
Discussion started by: agarwalniru
2 Replies
Login or Register to Ask a Question