Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Simple shell script to automatically move folder

  1. #11

    Re: Simple shell script to automatically move folder

    Quote Originally Posted by dwhitney67 View Post
    How does one then remove the space at the end of the resulting 'series_name'?

    If the file has the format of "foo foo - 3x11", and I use the statement you have shown above, the resulting 'series_name' is "foo foo " (note the trailing white-space).

    P.S. I ask the simple question above because, believe it or not, earlier today I thought of the suggestion you offered, and naturally I encountered a problem with it.
    have you tried sed?

    Code:
    series_name=`echo $1 | awk -F"-" '{ print $1 }' | sed 's/ $//'`
    or awk

    Code:
    series_name=`echo $1 | awk -F"-" '{ print $1 }' | awk '{ sub(/ $/, ""); print }'
    i'm sure this can be done with only one pipe, but i'm not quite sure how....

  2. #12
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,274
    Distro
    Kubuntu

    Re: Simple shell script to automatically move folder

    Ok, that works! I learn something new everyday.

  3. #13
    Join Date
    Oct 2007
    Location
    Vanløse, Denmark
    Beans
    39

    Re: Simple shell script to automatically move folder

    So how is that implemented into the script?
    And can i run that as root?

    Thanks.

    /knutz

  4. #14
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,274
    Distro
    Kubuntu

    Re: Simple shell script to automatically move folder

    Quote Originally Posted by knutz View Post
    So how is that implemented into the script?
    And can i run that as root?

    Thanks.

    /knutz
    Code:
    #!/bin/bash
    
    # change DEST to be the root-directory
    # where you want your new folders created.
    DEST="/"
    
    series_name=`echo $1 | awk -F"-" '{ print $1 }' | sed 's/ $//'`
    season_num=`echo $1 | awk -F"-" '{ print $2 }' | awk -F"x" '{ print $1 }' | awk -F" " '{ print $1 }'`
    
    mkdir -p "$DEST/$series_name/Season $season_num"
    mv "$1" "$DEST/$series_name/Season $season_num"
    To run the script as root, use sudo. For example:
    Code:
    sudo scriptName <folder>
    Last edited by dwhitney67; December 10th, 2009 at 02:12 AM.

  5. #15
    Join Date
    Oct 2007
    Location
    Vanløse, Denmark
    Beans
    39

    Re: Simple shell script to automatically move folder

    Quote Originally Posted by dwhitney67 View Post
    Code:
    #!/bin/bash
    
    # change DEST to be the root-directory
    # where you want your new folders created.
    DEST="/"
    
    series_name=`echo $1 | awk -F"-" '{ print $1 }' | sed 's/ $//'`
    season_num=`echo $1 | awk -F"-" '{ print $2 }' | awk -F"x" '{ print $1 }' | awk -F" " '{ print $1 }'`
    
    mkdir -p "$DEST/$series_name/Season $season_num"
    mv "$1" "$DEST/$series_name/Season $season_num"
    To run the script as root, use sudo. For example:
    Code:
    sudo scriptName
    Now this works!

    Thank you VERY much!!

    /knutz

Page 2 of 2 FirstFirst 12

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
  •