deleting specific parts of a line

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Mike Davies
Posts: 7
Joined: Tue Apr 24, 2012 7:49 pm

deleting specific parts of a line

Post by Mike Davies »

As a newbie, I've been trying to find some stuff on this but am bewildered!

I have a bunch of text files (200+) with tab-delimited data like that below (with \t added to show the tabs). Each file has up to 30000 lines of data all in the same format but I want to delete the Field with addresses ie the data I've highlighted in bold between tabs 8 and 9 (eg 65 Roads Ave H on line 1 and 25 Street 6 on line 2) across all the files.

I just can't work out the regex and I'd be very grateful for any suggestions. TextPad is great but their helpfiles do not help much! Thanks


Smith\tPeter\tM\t26020\t213\t300\t1\ta\t65 Roads AveH\t130556\tNorthern
Wilson\tJ M\tM\t20059\t214\t301\t2\tb\t25 Street 6\t130556\tWestern

:(
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: ^(([^\t]*\t){8})[^\t]*\t
Replace with: \1

[X] Regular expression

Replace All
Mike Davies
Posts: 7
Joined: Tue Apr 24, 2012 7:49 pm

Post by Mike Davies »

Brilliant! Thank you
Mike Davies
Posts: 7
Joined: Tue Apr 24, 2012 7:49 pm

replace only the tab

Post by Mike Davies »

so if I only wanted to replace say the 8th tab with a character like "-", would I enter this regex?

Find what: ^(([^\t]*\t){5})[^\t]*\t
Replace with: \-

damn but regex are confusing!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

No. You would use something like
Find what: ^(([^\t]*\t){7}[^\t]*)\t
Replace with: \1-
If a subexpression of a regex is parenthesised, the text it matches is captured and can be used in the replacement. The parentheses are numbered from left to right by the position of their left parenthesis symbols. In the replacement expression, \1 represents what was captured by the first parenthesised expression, \2 represents what was captured by the second, and so on.
Mike Davies
Posts: 7
Joined: Tue Apr 24, 2012 7:49 pm

Post by Mike Davies »

That's such a help, Ben, thank you.

I read that paragraph out to my wife and she just shook her head, said "furrrrrrrrrrrrrk" and walked away
Post Reply