79

I have a log file and I need to remove the first 27 characters off every line. You would have a line like this:

2011-09-25 01:25:29 [INFO] <Exazoro> wazup

But it needs to be like this:

<Exazoro> wazup
2
  • you could use some varient of the unix cut command from unxutils or busybox to do that much more easily - does it have to be notepad++?
    – Journeyman Geek
    Sep 25, 2011 at 10:21
  • @JourneymanGeek it dosn't have to be notepad++ its just waht i mainly use and it has macro and plugin support so i guessed there might be something to do that.
    – Mythrillic
    Sep 25, 2011 at 10:24

6 Answers 6

102

Use regular expression search, search for ^........................... and replace with (empty string).

enter image description here

Unfortunately, Notepad++ does not support repetition counts like ^.{27} — the SciTE regexp documentation applies here as well.


Alternatively, use rectangular multi-line selection (press Alt while selecting) to select these first 27 characters in every line, then press Delete or Backspace.

enter image description here


Using Unix tools (e.g. Cygwin, UnxUtils) you can use cut -c28- or sed -E "s|^.{27}||" instead. At least, these are the Linux command line calls you'd use...

9
  • 30
    Alt + Shift + right to select the 27 characters in the first row, then Pg Dn whilst still holding Alt + Shift should do it
    – icc97
    Sep 25, 2011 at 11:25
  • 1
    For the regex, Notepad++ doesn't follow all the standard regex rules, so I'm not surprised that you couldn't get it to work. And since it looks like the first 27 characters are a date, time, and error level, a more informative regex might be possible, like ^[0-9\-]+ [0-9:]+ \[[A-Z]+\]
    – MBraedley
    Sep 25, 2011 at 12:46
  • 5
    Loving the Alt for rectangular selection!!
    – Gromer
    Sep 14, 2012 at 21:27
  • Alt selection simple and easy. Thanks Daniel Beck. Apr 9, 2013 at 17:49
  • 1
    wow! thanks for that rectangular selection tip... I wasn't even aware that something like that exists...
    – Fr0zenFyr
    Sep 3, 2014 at 7:49
15

Since Daniel Beck's answer was originally posted, updates to Notepad++ now support the following regular expression repetition: ^.{27} But note with just that expression, Notepad++ will repeatedly remove all characters from the document until no more than 27 remain. To avoid this you can use the following Find/Replace:

  • Find what: ^.{27}(.*)$
  • Replace with: $1
3
  • this works perfectly!
    – Rudy
    Apr 29, 2019 at 5:39
  • This solution works in sublime as well!
    – neelmeg
    Jul 4, 2022 at 11:24
  • This one actually worked for me.
    – Abu Zaid
    Nov 27, 2023 at 13:21
6

Below is the macro way. This is more intuitive for non-technical people:

1) Place cursor on the first line (any cursor position)

2) Click : Macro -> Start Recording

3) Do the following key press activities:

* Press the Home key  
* Press Delete key 27 times (till you reach the intended character)
* Press down arrow button. 

4) Click : Macro -> Stop Recording

5) Click : Run Macro Multiple times -> select Run until the end of file -> click Run.

2

a small improvement to Daniel Beck answer:
Use regular expression search, search for:

^...........................(.*.\r\n) 

and replace with:

\1
2

ALT + SHIFT + Mouse selection (only ALT is not working)

Point at the beginning of the file, go to the end hold ALT+SHIFT and point on the position u want to...

0
0

Sometimes its removing the pattern after starting character as well, & when macro isn't a solution, alt+shift+right drag drop is also not possible because of large data for which someone need to work then below might work.

I have the error file in format of

[19 Aug 2022 00:00:00:021] ERROR TaskUtils$LoggingErrorHandler::handleError:95 - Unexpected error occurred in scheduled task.

For which need to remove [19 Aug 2022 00:00:00:021] for which simple but effective solution I used,

  1. Copy the data CSV format
  2. open in excel
  3. Data--> text to columns
  4. delimiter used "]" as in this case I do want separation from here
  5. Excel done separated out [19 Aug 2022 00:00:00:021] and those error text in just a minute.

Hope some one get this useful. By this I was able to remove all leading unwanted logging character for large file.

1
  • Avoid posting answers to old questions that already have well received answers unless you have something substantial and new to add.
    – Toto
    Aug 22, 2022 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .