Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    8

    Unanswered: how to split string?

    my old program is using cut to get the date of the file such:
    for FILE in ATK*
    do
    file_year=$(echo $FILE| cut -c 13-16)
    file_month=$(echo $FILE|cut -c 13-18)
    ###
    echo $file_month --->just as example!
    done
    where filename is such:
    ATK_7B1_WIP_20041116160700.1.xml.dsc
    ATK_7B1_WIP_20041116160700.2.xml.dsc
    ATK_7B1_WIP_20041116160700.3.xml.dsc
    ATK_7B1_WIP_20041116160700.4.xml.dsc

    problem is how can i enhance it to all filename?
    such:
    AIT_7B1_WIP_20050101010101.dsc
    ASECL_7B1_WIP_20041209151027.xml.dsc
    ASEKR_7B1_WIP_20050101020202.dsc

    so i cant use the ' for FILE in ATK* ' rite?
    should replace with what?
    all the filename will be the same unless the front name:
    xxxx_7B1_WIP_20041116160700xxx
    help!!!

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Code:
    for FILE in ATK*
    do
        date=$(echo ${FILE} | sed -e 's/.*_\([0-9][0-9]*\).*/\1/g')
        file_year=$(echo $date| cut -c 1-4)
        file_month=$(echo $date|cut -c 5-6) 
        .......
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

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