Manipulating, Aligning data without RegExp
Posted: Fri Jul 11, 2003 9:49 pm
When trying to do a Search or Replace, sometimes its hard to come up w/ RegExp, so what I do is use a combination of Replace and Block Select Mode.
Heres a simple example:
Lets say my goal is to align the second items in each line.
1) Press F8 (Replace)
Type "," (1 comma) in Find-What
Type ", " (1 comma then space) in Replace-With
Press Replace-All. Keep pressing this until you see each item being "pulled apart" from each other. See example below.
2) Press SHIFT+F10 then B (Block Select Mode)
Highlight the columns beginning from the s in snowpeas up to the first line making sure that the spaces in front of pears (line1), mango (line2), lime (line3), lime (line4) are highlighted.
3) Press F8 (Replace)
Type " " (1 space) in Find-What
Type "" (nothing) in Replace-With
Press Replace-All. See example below.
TADA!!
4) Now lets take this a step further. Our second goal is to replace all the words "lime" with "grapes" if they appear as the second item of each line.
While still in Block Select Mode, highlight all the columns covering all the words pears (line1), mango (line2), lime (line3), lime (line4), snowpeas (line5).
Press F8 (Replace)
Type "lime" in Find-What
Type "grapes" in Replace-With
Press Selected-text
Press Replace-All
See example below.
TADA!!
I think the important thing to remember is finding a pattern in your data (in this case, it was the comma), then using that pattern to "pull apart" items by adding a space character, then further manipulating them.
Heres a simple example:
Lets say my goal is to align the second items in each line.
Code: Select all
banana, pears, apple
lemon, mango, pineapple, lime
avocado, lime, pepper, apple
green beans, lime, apple
lime, snowpeas, carrotsType "," (1 comma) in Find-What
Type ", " (1 comma then space) in Replace-With
Press Replace-All. Keep pressing this until you see each item being "pulled apart" from each other. See example below.
Code: Select all
banana, pears, apple
lemon, mango, pineapple, lime
avocado, lime, pepper, apple
green beans, lime, apple
lime, snowpeas, carrotsHighlight the columns beginning from the s in snowpeas up to the first line making sure that the spaces in front of pears (line1), mango (line2), lime (line3), lime (line4) are highlighted.
3) Press F8 (Replace)
Type " " (1 space) in Find-What
Type "" (nothing) in Replace-With
Press Replace-All. See example below.
Code: Select all
banana, pears, apple
lemon, mango, pineapple, lime
avocado, lime, pepper, apple
green beans, lime, apple
lime, snowpeas, carrots4) Now lets take this a step further. Our second goal is to replace all the words "lime" with "grapes" if they appear as the second item of each line.
While still in Block Select Mode, highlight all the columns covering all the words pears (line1), mango (line2), lime (line3), lime (line4), snowpeas (line5).
Press F8 (Replace)
Type "lime" in Find-What
Type "grapes" in Replace-With
Press Selected-text
Press Replace-All
See example below.
Code: Select all
banana, pears, apple
lemon, mango, pineapple, orange
avocado, grapes, pepper, apple
green beans, grapes, apple
lime, snowpeas, carrotsI think the important thing to remember is finding a pattern in your data (in this case, it was the comma), then using that pattern to "pull apart" items by adding a space character, then further manipulating them.