Change field3 based on Field2 (If not this than 0)

General questions about using TextPad

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

Post Reply
steve1040
Posts: 39
Joined: Fri Oct 13, 2006 2:19 am

Change field3 based on Field2 (If not this than 0)

Post by steve1040 »

I have a CSV file with 3 columns

Field1,Field2,Field3

Example
123,SLSSYS1000,1
123,SLSSYS1000,1
123,SLSSYS1008,1
323,SLSSYS1000,1
323,SLSSYS1008,1
323,SLSSYS1000,1
321,SLSSYS1008,1
321,SLSSYS1000,1
321,SLSSYS1000,1

I would like to change the 1 to 0 if Field2 does not match SLSSYS1008

So my output would look like this
123,SLSSYS1000,0
123,SLSSYS1000,0
123,SLSSYS1008,1
323,SLSSYS1000,0
323,SLSSYS1008,1
323,SLSSYS1000,0
321,SLSSYS1008,1
321,SLSSYS1000,0
321,SLSSYS1000,0

Note: I have both Wildedit and Textpad

Is this possible in either tool?

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

Post by ben_josephs »

In TextPad:

Use Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Two steps:

Change field 3 to 0 in all records:
Find what: (^[^,]+,[^,]+),[^,]+$
Replace with: \1,0

[X] Regular expression

Replace All
Then change field 3 to 1 in records where field 2 is SLSSYS1008:
Find what: (^[^,]+,SLSSYS1008),[^,]+$
Replace with: \1,1

[X] Regular expression

Replace All
In WildEdit:

One step:

Change field 3 to 0 in records where field 2 is not SLSSYS1008:
Search for: (^[^,]+,(?!SLSSYS1008)[^,]+,)[^,]+$

[X] Regular expression

Replace with: $1,0

[ ] Literal replacement [i.e., not selected]
Post Reply