Ubuntu – gedit: search and replace with regular expressions

gedit

I want to replace this with gedit:

 1299465 |  2003415 | 2015-09-06 05:35:34.59662+02
 1299449 |  2009400 | 2015-09-06 05:35:32.301683+02
 1299450 |  2008465 | 2015-09-06 05:35:32.451393+02
 1299457 |  2015211 | 2015-09-06 05:35:33.451049+02

to that:

2003415
2009400
2008465
2015211

How can I do this with gedit?

Background: I want to do it with gedit and not sed/python/…. since the replace needs to be done interactive.

Best Answer

From the standard Replace box (Control+H) you can use a little grouped regex to handle this:

  • Search for: .*\| (.*) \|.*
  • Replace with: \1
  • Check the box that has "Match as regular expression"

This is on Gedit 3.10.4, the default version in Ubuntu 14.04.