GrumP
GrumP

Reputation: 1203

Macro to format strings inside notepad++

I have a large list of data I want to convert into a different format without doing it manually. I believe there should be a way of creating a macro of sorts to make this task far less time consuming in the long run!

My data looks like:

EquipmentHire = 99

EquipmentPurchase = 100

EquipmentSpec = 101

and so on. I want it all converted to look like this instead: (so I can load it into a database)

INSERT INTO table_name VALUES (99, ‘EquipmentHire’);

Can anyone help me out? Thanks. :)

Upvotes: 1

Views: 1199

Answers (1)

OCary
OCary

Reputation: 3311

I've done similar tasks in MS-Excel using string concatenation and string manipulation functions like substring(), charindex().

Basically, open your text file in Excel (assuming text will be in column A), set column B to be your string manipulation of column A, copy the formula down for all rows, and then copy the column B contents to a new text file.

If this is a one-off, that would be a faster approach for me than writing a macro. I also did something like this via a powershell script a while back, but again, for a one-off Excel was faster for me.

Added --

Excel sample formula. This is very, very format dependent. If your data is always a consistent format (exact number of spaces around the equals sign, etc). Perl, powershell, macro, etc etc will likely be a better approach if you need to do this often, or your format is going to vary by spaces, etc.

Assuming EquipmentHire = 99 is the contents of A1, the following would be in cell B1 to give you your SQL statement.

="INSERT INTO table_name VALUES ("&MID(A1,FIND("=",A1)+2,1000)&", '" & MID(A1,1,FIND("=", A1)-2) & "');"

Tested using sample data in original post and MS-Excel 2k10

Upvotes: 1

Related Questions