How to delete a stipulated number of letters at the beginning of each line?
-
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
gsgsuxnsxuycbxhbshbxshxbkjsxsxmksI 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.
-
@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.
-
@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. -
@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.
Terry