I need to write a script that will...

Discussion in 'OT Technology' started by PJThomas, Jan 8, 2004.

  1. PJThomas

    PJThomas Member

    Joined:
    Jun 6, 2002
    Messages:
    611
    Likes Received:
    0
    Location:
    Massachusetts
    ...change file extensions from .dat to .igs. Does anyone know how to do this? The files are all in the same folder if that makes a difference. Thanks in advance.
     
  2. col_panic

    col_panic calm like a bomb Moderator

    Joined:
    Sep 19, 2003
    Messages:
    188,160
    Likes Received:
    0
    Location:
    winter haven, fl
    mv *.dat *.igs

    edit: sorry - that doesn't work on win32 (might work on unix)

    use ren instead of mv
     
  3. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,486
    Likes Received:
    614
    What os are you using?

    In a windows dos box you can just do
    ren *.dat *.igs
    like col panic said.
     
  4. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,486
    Likes Received:
    614
    In unix it's a little more complicated. You can do something like this:

    for i in *.dat
    do j=`echo $i | sed 's/dat$/igs/'`
    mv "$i" "$j"
    done
     
  5. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,458
    Likes Received:
    12
    Yeah, it's `ren *.dat *.igs` under windows, but you can't use mv *.dat *.igs under UNIX.

    What I do is:

    ls -1 *.dat | sed "s/\(.*\)\.dat$/mv '&' '\1.igs'/" | sh

    Or use a for loop

    for i in `ls -1 *.dat`
    do
    mv $i `echo $i | sed s/".dat"/".igs"/g`
    done
     
  6. PJThomas

    PJThomas Member

    Joined:
    Jun 6, 2002
    Messages:
    611
    Likes Received:
    0
    Location:
    Massachusetts
    Thanks
     

Share This Page