Community
    • Login

    Help needed :) Automate deleting number and spacing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 2.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nazrulsyah Firaz Fauzee AndylimN
      Nazrulsyah Firaz Fauzee Andylim
      last edited by

      Hi,

      I have files with the below format. FYI, there is a spacing between ‘2’ and '10:00:01:00 ', it is some sort induced by the ‘Tab’ key.
      2 10:00:01:00 10:00:02:07
      When I was a child,

      How can I change it to this format without having to do it manually?
      10:00:01:00 10:00:02:07
      When I was a child,

      I really appreciate your advise and assistance! Thanking you in advance :)

      Cheers

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Nazrulsyah Firaz Fauzee Andylim
        last edited by

        @Nazrulsyah-Firaz-Fauzee-Andylim

        What does mean automate in this context?
        You open the file and it should magically disappear?
        You wanna click a button/execute a script?
        Anything else?

        There are several solutions I can think of.

        1. Record a macro which puts the cursor into the start of the line, press
          delete twice, move cursor to the next line - done - save macro and run it multiple times.

        2. Use search and replace with a regex like

          ^\d+\s+
          

        keep replace field empty press replace.
        3) Use column mode by pressing left ALT key and select the columns to be removed,
        press delete.
        4) …

        If non of these answer the question, please be more specific what you want and
        how data could look like.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Nazrulsyah Firaz Fauzee AndylimN
          Nazrulsyah Firaz Fauzee Andylim
          last edited by

          Thank you Claudia. Allow me to rephrase my query.

          These files are in TXT format and I want to have it either in TXT or SRT as the final format.
          The original TXT file looks like this.
          2 10:00:01:00 10:00:02:07
          When I was a child,

          This is how I want it to look like.
          10:00:01:00 10:00:02:07
          When I was a child,

          I have 62 files to work on and I am not that sure how to do it in the fastest way. Btw, I tried using your #2 suggestion (regex), but it did not work. I am using Mac.

          1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones
            last edited by

            FIND = ^\d\s+(\d+:)
            REPLACE = \1

            Input:

            1 10:18:75 20:17:21
            blah blah
            blah blah
            
            2 11:13:55.555  12:13:14
            one
            
            3 11:16:21 15:22:34,356
            more than one
            line in the SRT
            goes here
            

            Output

            10:18:75 20:17:21
            blah blah
            blah blah
            
            11:13:55.555  12:13:14
            one
            
            11:16:21 15:22:34,356
            more than one
            line in the SRT
            goes here
            

            But if you happen to have text in your caption that looks like a number followed by the time,

            2 10:15:16 10:20:30
            normal caption
            
            3 11:16:21 15:22:34,356
            And my song goes
            1 1:21 in the afternoon,
            even though that's a silly song
            

            … it will also match the “1 1:21” and change it to “1:21”. If that’s a remote possibility for your captions, @-mention guy038, and ask him how to modify my regex to require either beginning of file or a blank line followed by my regex. I know such things are possible in regex (using lookbehinds, etc), I’m just not that good.

            1 Reply Last reply Reply Quote 0
            • guy038G
              guy038
              last edited by guy038

              Hello Nazrulsyah Firaz Fauzee Andylim, Peter Jones and All

              If I fully understand the problem, your first line begins with one or more digits, followed by any spacing, followed by two time values, each of them, separated by a space and written with the template HH:MM:SS:CC ( CC = hundredth of second , from 00 to 99 )

              And you would like to delete the first number, at beginning of each line, containing the templates HH:MM:SS:CC, on 62 files, wouldn’t you ? If so :

              • Backup your 62 TXT files, as the same 62 SRT files ( IMPORTANT )

              • Open the Find in files dialog ( Ctrl + Shift + F )

              • In the Find What : zone, type ^\d+\h+(?=\d\d:\d\d:\d\d:\d\d)

              • Leave the Replace with : zone EMPTY

              • In the Filters zone, type *.SRT

              • In the Directory zone, type the absolute location of these 62 SRT files

              • Select the Regular expression search mode

              • Uncheck, if necessary, the In all sub-folders and In hidden folders options

              • Click on the Replace in Files button and click on the OK button to valid that S/R

              Et voilà !

              Remark : If anything goes wrong, NO panic : just, delete the 62 SRT files, as you STILL get the 62 original TXT files :-)

              For instance, from the text below :

              2 15:25:23:80 15:25:25:37
              Blah, blah
              Blah, blah
              Blah, blah
              
              .........
              .........
              
              7     10:00:01:00 10:00:02:07
              When I was a child, I used to go,
              2 times per week, to Mr Parker's work-shop
              to contemplate, with fascination, all the
              automatons, build by the old man. More than
              1 hundred, with their sparkling colours, lay
              on numerous shelves...
              
              .........
              .........
              
              11 03:07:59:77 03:08:01:13
              more than one
              line in the SRT
              goes here
              

              you would obtain, the replaced text below :

              15:25:23:80 15:25:25:37
              Blah, blah
              Blah, blah
              Blah, blah
              
              .........
              .........
              
              10:00:01:00 10:00:02:07
              When I was a child, I used to go,
              2 times per week, to Mr Parker's work-shop
              to contemplate, with fascination, all the
              automatons, build by the old man. More than
              1 hundred, with their sparkling colours, lay
              on numerous shelves...
              
              .........
              .........
              
              03:07:59:77 03:08:01:13
              more than one
              line in the SRT
              goes here
              

              Notes :

              • Only, the three numbers 2, 7 and 11, at beginning of lines, and the following spacing characters, are deleted

              • Luckily, the lines, which begin with a number, but not followed by a template, of the form HH:MM:SS:CC, remain unchanged !

              • From beginning of line ( ^ ), the regex engine looks for a non null range of digits ( \d+ ), followed by some non null spacing characters ( \h+ ).

              • Then, due to the syntax (?=\d\d:\d\d:\d\d:\d\d), named a positive look-ahead, the regex engine, verifies that, at cursor position, a time value, with the template HH:MM:SS:CC can be found. If so, the overall regex matches that initial number and the spacing, after it.

              • And, as the Replace zone is EMPTY, it’s , simply, deleted, from the file’s contents

              Best Regards,

              guy038

              P.S. :

              BTW, are my two sentences, at middle of the text, looks like “fair” English prose ?!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors