• Login
Community
  • Login

How to delete a stipulated number of letters at the beginning of each line?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 9.0k 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.
  • E
    Emalino Emalero
    last edited by Aug 8, 2022, 10:54 PM

    Suppose I have a txt with more than 1000 lines, I want to delete the first 5 letters or characters from the beginning of each of the 1000 lines, is there a way to do this in notepad++? Some programs to rename multiple files have this option, but in text editors I didn’t find this option. Maybe I didn’t find this option because I’m a noob, or because such an option doesn’t exist. Thanks for listening. Example:

    ahjuygbmnewwpflfwlpmvpmkrmvkrmr
    ardwq5yeqnqçweflUaNBTWIWQOKI
    jjbdywdsampmndbjnmcjhdystrwxjkujh
    gsgsuxnsxuycbxhbshbxshxbkjsxsxmks

    I want to delete the first five letters, or any other number I specify, at the beginning of every line in the file. Manually doing this on a file with more than a thousand lines is a drag.

    T 1 Reply Last reply Aug 8, 2022, 11:28 PM Reply Quote 0
    • T
      Terry R @Emalino Emalero
      last edited by Aug 8, 2022, 11:28 PM

      @Emalino-Emalero said in How to delete a stipulated number of letters at the beginning of each line?:

      I want to delete the first five letters, or any other number I specify, at the beginning of every line in the file.

      It is simple. When you use regular expressions you select characters then perform operations on them. In this case we select the 5 characters you want to remove, then select the remainder of the line and in the second selection we save these. Then in the “write back” field we return those characters we wish to keep. So in effect we remove the first 5 characters. If you need to change how many characters to remove, you change the number 5 in the “find what” field as shown below to the new number.

      Find What:(?-s)^.{5}(.+\R?)
      Replace With:${1}

      So this uses the “Replace” function, and search mode must be “regular expression”. Copy the red text above into each of the fields, making sure the search mode is set to “regular expression”. Then either click on “Replace” or “Replace All” button to make the change 1 line at a time, or all the lines at once.

      Terry

      PS regular expressions can be quite powerful, so if you’d like to learn, have a look in our FAQ section. There is lots of information about various things, and links to good reading material on regular expressions.

      E 1 Reply Last reply Aug 9, 2022, 12:02 AM Reply Quote 2
      • E
        Emalino Emalero @Terry R
        last edited by Aug 9, 2022, 12:02 AM

        @Terry-R
        Thank you very much man! Saved my week, worked perfectly. For the document I was editing I had to replace the 5 with 15 and it was perfect. An amateur doubt…? Wouldn’t it be possible to implement this function in text mode in the program? I believe that even for some users with medium to advanced knowledge, it is not easy to master these codes.

        T 1 Reply Last reply Aug 9, 2022, 12:09 AM Reply Quote 0
        • T
          Terry R @Emalino Emalero
          last edited by Aug 9, 2022, 12:09 AM

          @Emalino-Emalero said in How to delete a stipulated number of letters at the beginning of each line?:

          Wouldn’t it be possible to implement this function in text mode in the program?

          Possible yes, probable, unlikely. Since this uses a rudimentary expression that easily covers the process.

          There is another idea that works without regular expressions, it involves the use of a box that covers all 5 characters of all the lines. So you use Ctrl+Alt+mouse button which allows creating a box around the first 5 characters (or any number). Then you’d delete.
          fb8ef8c0-5aba-446b-90b4-83b47e3f7ad8-image.png

          Terry

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