Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Linux Move/Rename file

    I need to be able to strip the _DateStamp from a filename, use the resulting filename to create a directory and then move the file to the created directory without the Date Stamp in the filename.

    So 'blah_120709.rec' moves to a file 'blah.rec' in directory 'blah'.

    I've done some searching and found lots of posts about awk and sed but I'm afraid they're over my head.

    Could someone help me with a Linux script that will do this.

    Thanks in advance




  2. #2
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by captain747480 View Post
    I need to be able to strip the _DateStamp from a filename, use the resulting filename to create a directory and then move the file to the created directory without the Date Stamp in the filename.

    So 'blah_120709.rec' moves to a file 'blah.rec' in directory 'blah'.

    I've done some searching and found lots of posts about awk and sed but I'm afraid they're over my head.

    Could someone help me with a Linux script that will do this.

    Thanks in advance
    try this:

    for i
    do
    base_name=`echo $i | sed -n 's/\(.*\)_[0-9]*\.rec/\1/p'`
    if [ -n "${base_name}" ]
    then
    mkdir ${base_name}
    mv $i ${base_name}/${base_name}.rec
    else
    echo "$i is bad"
    fi
    done



    from within a directory containing the files:
    script.sh *.rec

  3. #3
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks

 

 

Similar Threads

  1. Rename all files to lowercase?
    By Charles1718 in forum Command Line
    Replies: 6
    Last Post: 07-09-2012, 06:53 AM
  2. Replies: 0
    Last Post: 02-14-2012, 08:16 AM
  3. Replies: 0
    Last Post: 01-05-2012, 11:40 AM
  4. Replies: 0
    Last Post: 12-13-2011, 01:06 AM
  5. Replies: 0
    Last Post: 12-05-2011, 07:00 PM

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
  •  
           








Check out Linux Central for Linux software and other goodies!





» Stats

Members: 3,580
Threads: 3,920
Posts: 9,446
Top Poster: Fred (1,486)
Welcome to our newest member, SLW210

» Links



Powered by vBadvanced CMPS