Find the answer to your Linux question:
Results 1 to 3 of 3
Oh man.. this is so annoying. I am a freelance photographer.. and when I get print orders they come in as a huge text file, it was taking forever to ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    2

    Bash driving me nuts... :(

    Oh man.. this is so annoying.

    I am a freelance photographer.. and when I get print orders they come in as a huge text file, it was taking forever to copy all the prints into another folder so the application that does the ordering could be run over the folder to place the print orders with my lap.

    As a result.. I had a friend of mine (who is no longer with us) create a little bash script that I can run over the text file to move the prints.. it's very simple:

    Code:
    #!/bin/bash
    for x in $(cat images.txt); do
    	cp $x print/
    done
    However, what we didn't plan for is that sometimes people include two or three or four etc orders of the same image.. when this happens.. the file is simply over-written and I have no way to know that there is a second order.. I don't know anything about bash and I've been researching how to correct this problem for about 2 months now, I am no closer.. I wondered if possibly someone might show me what needs to be added to this script to create either another copy right a different file name, or some way of identifying two prints.

    Also, I suspect I should share... I'm not technically using linux, I run OS X.

    Thank you for your time.

    j.

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Never worked with OS X but this script works in bash. It appends a number (.2, .3, etc) if the file already exists:

    Code:
    #!/bin/bash
    
    typeset -i ct
    for x in $(cat images.txt); do
            fle="`basename $x`"
            if [ -e print/$fle ]
               then ct=1
                    lp="y"
                    while [ "$lp" = "y" ]
                        do
                            ct=ct+1
                            tmp="${fle}.$ct"
                            if [ ! -e print/$tmp ]; then lp="n"; fi
                        done
                    echo "file renamed to: $tmp"
                    fle="$tmp"
               fi
            cp $x print/$fle
    done

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Posts
    2

    Thank you.

    Thank you so much, that really helped.

    If you ever need any wedding photography.. Still-Motion.ca Photo . Video - Hit me up, we'll sort it out for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...