Retaining only specific lines of text
Posted: Tue Jan 24, 2012 3:07 pm
Hi,
Just re-discovered this forum which I joined years ago and had forgotten about!
I was initially going to call this subject
'Deleting many lines of text between specified characters?
but I suppose they're essentially equivalent?
Anyway, although a TextPad veteran I'm a relative Regex novice and hoping one of the experts can help please. I have a text file that looks like this:
--- Start paste ---
[BlackfordLane.jpg]
File name = BlackfordLane.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 87, subsampling OFF
Resolution = 96 x 96 DPI
File date/time = 19/01/2012 / 15:01:23
- IPTC -
Object Name - s bridge over the River Thames is not a footbridge but carries pipes.
- COMMENT -
Thames Path on Blackford Lane heading towards Blackford Farm, east of Castle Eaton.
[Castle Eaton Church.jpg]
File name = Castle Eaton Church.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 87, subsampling OFF
Resolution = 72 x 72 DPI
File date/time = 19/01/2012 / 14:03:55
- EXIF -
Make - FUJIFILM
Model - FinePix2600Zoom
Orientation - Top left
XResolution - 72
YResolution - 72
ResolutionUnit - Inch
- COMMENT -
Castle Eaton Church
[CastleEaton-2.jpg]
File name = CastleEaton-2.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 75
Resolution = 0 x 0 DPI
File date/time = 18/01/2012 / 15:40:05
- COMMENT -
The Red Lion, Castle Eaton
A warm welcoming pub on a cold winter's day, with the River Thames running at the bottom of the garden.
--- End paste ---
And this is what I want to get as a result:
--- Start paste ---
BlackfordLane.jpg
Thames Path on Blackford Lane heading towards Blackford Farm, east of Castle Eaton.
Castle Eaton Church.jpg
Castle Eaton Church
CastleEaton-2.jpg
The Red Lion, Castle Eaton
A warm welcoming pub on a cold winter's day, with the River Thames running at the bottom of the garden.
--- End paste ---
My first line of attack is to try for a Regex expression that will Find everything (for example) between the ']' of '[BlackfordLane.jpg]' and the '-' of '- COMMENT -'? That would leave only a little tidying up, I think.
But so far that's eluded me after some hours. The best I could come up with was the following to delete all lines from File name... to File date/time.
Find:
File name = .*\nDirectory = .*\nCompression = .*\nResolution = .*\nImage dimensions = .*\nPrint size = .*\nColor depth = .*\nNumber of unique colors = .*\nDisk size = .*\nCurrent memory size = .*\nFile date/time = .*\n
Replace:
(Nothing)
But that's only part of the task and seems very inelegant.
Any suggestions please?
I'm beginning to suspect TextPad can't do it and that I'll have to find the Filenames and Comments with separate Regex expressions then use my macro program to iterate down the entire file and assemble the cumulative result. But I hope someone can prove me wrong please!
--
Terry, East Grinstead, UK
Just re-discovered this forum which I joined years ago and had forgotten about!
I was initially going to call this subject
'Deleting many lines of text between specified characters?
but I suppose they're essentially equivalent?
Anyway, although a TextPad veteran I'm a relative Regex novice and hoping one of the experts can help please. I have a text file that looks like this:
--- Start paste ---
[BlackfordLane.jpg]
File name = BlackfordLane.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 87, subsampling OFF
Resolution = 96 x 96 DPI
File date/time = 19/01/2012 / 15:01:23
- IPTC -
Object Name - s bridge over the River Thames is not a footbridge but carries pipes.
- COMMENT -
Thames Path on Blackford Lane heading towards Blackford Farm, east of Castle Eaton.
[Castle Eaton Church.jpg]
File name = Castle Eaton Church.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 87, subsampling OFF
Resolution = 72 x 72 DPI
File date/time = 19/01/2012 / 14:03:55
- EXIF -
Make - FUJIFILM
Model - FinePix2600Zoom
Orientation - Top left
XResolution - 72
YResolution - 72
ResolutionUnit - Inch
- COMMENT -
Castle Eaton Church
[CastleEaton-2.jpg]
File name = CastleEaton-2.jpg
Directory = C:\Docs\My Videos\PROJECTS\Thames Path Walk Projects\TP03 Project\Geograph Photos\GeoDay2\
Compression = JPEG, quality: 75
Resolution = 0 x 0 DPI
File date/time = 18/01/2012 / 15:40:05
- COMMENT -
The Red Lion, Castle Eaton
A warm welcoming pub on a cold winter's day, with the River Thames running at the bottom of the garden.
--- End paste ---
And this is what I want to get as a result:
--- Start paste ---
BlackfordLane.jpg
Thames Path on Blackford Lane heading towards Blackford Farm, east of Castle Eaton.
Castle Eaton Church.jpg
Castle Eaton Church
CastleEaton-2.jpg
The Red Lion, Castle Eaton
A warm welcoming pub on a cold winter's day, with the River Thames running at the bottom of the garden.
--- End paste ---
My first line of attack is to try for a Regex expression that will Find everything (for example) between the ']' of '[BlackfordLane.jpg]' and the '-' of '- COMMENT -'? That would leave only a little tidying up, I think.
But so far that's eluded me after some hours. The best I could come up with was the following to delete all lines from File name... to File date/time.
Find:
File name = .*\nDirectory = .*\nCompression = .*\nResolution = .*\nImage dimensions = .*\nPrint size = .*\nColor depth = .*\nNumber of unique colors = .*\nDisk size = .*\nCurrent memory size = .*\nFile date/time = .*\n
Replace:
(Nothing)
But that's only part of the task and seems very inelegant.
Any suggestions please?
I'm beginning to suspect TextPad can't do it and that I'll have to find the Filenames and Comments with separate Regex expressions then use my macro program to iterate down the entire file and assemble the cumulative result. But I hope someone can prove me wrong please!
--
Terry, East Grinstead, UK