Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Posts
    29

    Unanswered: removing strings from filename

    if I have filenames like this k_tape_dis_06082004.txt , how can I remove the date string appearing in there using KsH ? so the file should look like
    k_tape_dis.txt

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Code:
    #!/bin/ksh
    
    file='k_tape_dis_06082004.txt'
    
    echo "file->[${file}] changed->[$(echo "${file}" | sed -e 's/^\(.*\)_\([0-9][0-9]*\)\(.*\)/\1\3/g')]"

  3. #3
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    ..... with the ksh's builtins:

    Code:
    #!/bin/ksh
    
    file='k_tape_dis_06082004.txt'
    
    echo "file->[${file}] changed->[${file%%_${file##*_}}.${file##*.}]"

Posting Permissions

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