Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Shell script to add the extension to doc and pdf files

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-02-2010
Member
 
Join Date: Jan 2010
Posts: 29
Shell script to add the extension to doc and pdf files

I am trying to develop a shell script which i will be using it in Linux, where i am trying to add an extension to a large number of pdf and doc files. Frankly speaking i don't have any idea about it but has some basic programming language, can anyone provide me with the code which can fulfill my requirements.
Reply With Quote
  #2  
Old 24-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Shell script to add the extension to doc and pdf files

If you really want to add extension to your doc and pdf files then i would suggest you to use the following code in your script and i am sure this will realy help you a lot.

Code:
/ bin / sh
for i in `ls-l | awk '(print $ 8)'`
do
var = $ (file $ i | grep-i pdf | awk '(print $ 2)')
if [ "$ var" == "PDF"] then
echo $ var;
cp $ i $ i.pdf;
else
cp $ i $ I.doc;
echo "BAD";
if;
Reply With Quote
  #3  
Old 24-02-2010
Member
 
Join Date: Jan 2010
Posts: 29
Shell script to add the extension to doc and pdf files

Thank you for replying me i had try to use the above code in my Shell script over here i am facing some issue where it copies all the files through .doc and teh code is not working for pdf files, can anyone tell me what's the exact issue with the code.
Reply With Quote
  #4  
Old 24-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Shell script to add the extension to doc and pdf files

Sorry i had done a very small mistake that i had inserted 2 equal sign instead of one, this is one of the reason for all the files get copy through the. Doc and not pdf files and i had made changes in the code have a look at it.

Code:
/ bin / sh
for i in `ls-l | awk '(print $ 8)'`
do
var = $ (file $ i | grep-i pdf | awk '(print $ 2)')
if [ "$ var" = "PDF"] then
cp $ i $ i.pdf;
else
cp $ i $ I.doc;
if;
Reply With Quote
  #5  
Old 24-02-2010
Member
 
Join Date: Feb 2009
Posts: 114
Re: Shell script to add the extension to doc and pdf files

Thats very kind of you guys, from a long back i was finding for such kind of script and over here i would like to share my knowledge if you want to watch the execution traces then you have to add the following code in your script

Code:
$> Bash-x monscript.sh
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Shell script to add the extension to doc and pdf files"
Thread Thread Starter Forum Replies Last Post
Shell extension on gnome 3.2 HangDown Operating Systems 8 06-01-2012 10:37 AM
PSD Shell Extension Problem Resource file C_PsdRsDll not found TAARIQ Operating Systems 4 05-11-2010 05:12 AM
Cutting a file into several files using shell script Shaan12 Software Development 3 23-10-2009 12:43 AM
Download GMail Drive shell extension Techguru01 Technology & Internet 4 04-03-2009 05:48 PM
Script to search for and delete all files with extension xxx Mike62 Windows Server Help 2 25-11-2006 10:58 PM


All times are GMT +5.5. The time now is 07:39 AM.