Loading ...
Sorry, an error occurred while loading the content.

automatically editing many .tec files

Expand Messages
  • אסף חיים פרייס
    Hi there, I ve many .tec files that been created after mistakly deleting photos on my android. I m trying to edit them, by deleting the 6 first chrs. and the
    Message 1 of 5 , Apr 19, 2014
    • 0 Attachment
      Hi there,
      I've many .tec files that been created after mistakly deleting photos on my android.
      I'm trying to edit them, by deleting the 6 first chrs. and the last one.
      Then, I'm changing the file from .tec to .jpg.
      I have 3000 files!!!
      Is there any way to make it automatically, like a script or cmd commands?
      Thanks for your kind help/
      Asaf

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Shlomi Fish
      Hi Asaf, On Sat, 19 Apr 2014 02:45:13 -0700 (PDT) ... Yes, there is. You can use the following Bash+Perl command: find . -name *.tec | (while read fn ; do
      Message 2 of 5 , Apr 19, 2014
      • 0 Attachment
        Hi Asaf,

        On Sat, 19 Apr 2014 02:45:13 -0700 (PDT)
        אסף חיים פרייס <preiss.asaf@...> wrote:

        > Hi there,
        > I've many .tec files that been created after mistakly deleting photos on my
        > android. I'm trying to edit them, by deleting the 6 first chrs. and the last
        > one. Then, I'm changing the file from .tec to .jpg.
        > I have 3000 files!!!
        > Is there any way to make it automatically, like a script or cmd commands?

        Yes, there is. You can use the following Bash+Perl command:

        find . -name '*.tec' | (while read fn ; do
        perl -n -0777 -e 'print substr($_,6,-1)' "$fn" > "${fn%%.tec}.jpg" ;
        done)

        Untested!

        (This snippet of code can be freely reused under the MIT/X11 License / Public
        Domain (CC0) )

        Regards,

        Shlomi Fish

        --
        -----------------------------------------------------------------
        Shlomi Fish http://www.shlomifish.org/
        The Case for File Swapping - http://shlom.in/file-swap

        Cast your bread upon the waters, for after many days you will find it again.
        — Ecclesiastes 1:11

        Please reply to list if it's a mailing list post - http://shlom.in/reply .

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • John Little
        Shlomi has given an all in one command which assumes a unix-like environment, but I suspect because cmd is mentioned that Asaf s on windows. While I like,
        Message 3 of 5 , Apr 20, 2014
        • 0 Attachment
          Shlomi has given an all in one command which assumes a unix-like environment, but I suspect because "cmd" is mentioned that Asaf's on windows.

          While I like, and use, single line do-it-all-at-once solutions, when there's a bunch of stuff one doesn't want to lose, or there's other pressures, a step by simple step approach, where one sees each step's results, can be good.

          So, I'd first create a file with the list of the file names. On windows, that would be, in a command window having changed to the right directory:

          dir /b *.tec > photos.bat

          (from rusty windows memory, we want a single column of file names, with no spaces at the beginning of each line)
          Then, open photos.bat in vim, and duplicate each name with two spaces between them:

          :%s/.*/& &/

          delete the first 6 characters after the spaces

          :%s/ ....../ /

          delete the first character before the dot at the end

          :%s/.\.tec$/.tec/

          change tec to jpg:

          :%s/tec$/jpg/

          add a rename command to the beginning of each line

          :%s/^/ren /

          save the file, exit vim, and run the batch file

          $ photos.bat

          On *n*x the first command would have "ls" instead of "dir /b", "ren" would be "mv", and the last would be

          $ sh photos.bat

          HTH, and regards, John Little

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Tim Chase
          ... John does an excellent job of breaking down each of the steps. If you want to do it in a single transformation pass, you can just do dir /b *.tec | vim -
          Message 4 of 5 , Apr 20, 2014
          • 0 Attachment
            On 2014-04-20 05:48, John Little wrote:
            > While I like, and use, single line do-it-all-at-once solutions,
            > when there's a bunch of stuff one doesn't want to lose, or there's
            > other pressures, a step by simple step approach, where one sees
            > each step's results, can be good.

            John does an excellent job of breaking down each of the steps. If
            you want to do it in a single transformation pass, you can just do

            dir /b *.tec | vim -
            :%s/.\{6}\(.*\).\.tec$/ren "&" "\1.jpg"
            :%!cmd

            The "$" *should* be optional, but sometimes crazy things happen with
            Win32 filenames (and their 8.3 shortenings), so I prefer to be
            explicit.

            I also went ahead and quoted the filenames in the event that any of
            them have spaces in them which can cause problems otherwise.

            -tim


            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • Jürgen Krämer
            Hi, ... you already got three solutions, but here is another one in the form of a batch file which only needs built-in commands of cmd.exe @echo off setlocal
            Message 5 of 5 , Apr 22, 2014
            • 0 Attachment
              Hi,

              אסף חיים פרייס wrote:
              >
              > I've many .tec files that been created after mistakly deleting photos on my android.
              > I'm trying to edit them, by deleting the 6 first chrs. and the last one.
              > Then, I'm changing the file from .tec to .jpg.
              > I have 3000 files!!!
              > Is there any way to make it automatically, like a script or cmd commands?
              > Thanks for your kind help/
              > Asaf
              >

              you already got three solutions, but here is another one in the form of
              a batch file which only needs built-in commands of cmd.exe

              @echo off
              setlocal enabledelayedexpansion

              for %%f in ( *.tec ) do (
              set fn=%%f
              ren "!fn!" "!fn:~6,-5!.jpg"
              )

              Regards,
              Jürgen

              --
              Sometimes I think the surest sign that intelligent life exists elsewhere
              in the universe is that none of it has tried to contact us. (Calvin)

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            Your message has been successfully submitted and would be delivered to recipients shortly.