Results 1 to 5 of 5

Thread: Shell script to add the extension to doc and pdf files

  1. #1
    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.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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;

  3. #3
    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    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;

  5. #5
    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

Similar Threads

  1. Script to search for and delete all files with extension xxx
    By Mike62 in forum Windows Server Help
    Replies: 3
    Last Post: 19-03-2012, 02:48 PM
  2. Replies: 4
    Last Post: 05-11-2010, 04:12 AM
  3. Cutting a file into several files using shell script
    By Shaan12 in forum Software Development
    Replies: 3
    Last Post: 22-10-2009, 11:43 PM
  4. Download GMail Drive shell extension
    By Techguru01 in forum Technology & Internet
    Replies: 4
    Last Post: 04-03-2009, 05:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,381,014.64665 seconds with 17 queries