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
Quick if file exist question... elbombillo UNIX Desktop for Dummies Questions & Answers 1 11-30-2008 12:45 AM
If file not exist create a new one din_annauniv Shell Programming and Scripting 3 05-28-2008 07:30 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
how to check if directory/file exist using c/c++ steven88 High Level Programming 2 01-03-2006 02:55 AM
how to check if the file exist or not? gusla UNIX for Dummies Questions & Answers 3 03-27-2002 10:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-11-2009
handband2 handband2 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 5
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 (permalink)  
Old 02-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
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 (permalink)  
Old 02-11-2009
handband2 handband2 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 5
Quote:
Originally Posted by vgersh99 View Post
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
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 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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