Post #275,448
12/11/06 10:26:37 AM
|
Help! How to programatically edit case of strings?
We have a file full of shtuff like <someTag><attr ibute="bl-ah">MY_STRING_VALUE</attr>, which we'd like to become more like <someTag><attr ibute="bl-ah">My_String_Value</attr>.
I suspect this should be possible to do with sed or awk or something -- which seem to be available on the client's proprietary Unix platform -- but I sure can't seem to come up with the correct incantations to do it on my own. :-(
One could easily change the <someTag><attr ibute="bl-ah"> and </attr> bits to something else temporarily (global search-and-replace in a text editor), if the <s, /s, and >s are a hindrance (and then change them back afterwards).
That would simplify(?) the problem to something like: Change @MY_STRING_VALUE\ufffd to @My_String_Value\ufffd throughout the file... And I don't know how to do that either. :-(
Anyone?
[link|mailto:MyUserId@MyISP.CountryCode|Christian R. Conrad] (I live in Finland, and my e-mail in-box is at the Saunalahti company.)
Ah, the Germans: Masters of Convoluted Simplification. — [link|http://www.thetruthaboutcars.com/?p=1603|Jehovah]
|
Post #275,449
12/11/06 10:38:29 AM
|
Problem restated
Camel case ALL text not found with angle brackets.
This seems to be what you are saying.
Or is is a matter of when we see a PARTICULAR tag, camel case the following string.
Or something else.
If you don't have Perl on the system, can you get the files on a system that does?
|
Post #275,489
12/11/06 3:53:22 PM
|
Particular - SOME tag, not any other tag.
Hmm... Yeah, if I installed Perl on my Windows (XP Pro) PC at work.
Anybody know an MS-Word macro to do the same thing? I already have Word on the box, wouldn't have to install anything.
[link|mailto:MyUserId@MyISP.CountryCode|Christian R. Conrad] (I live in Finland, and my e-mail in-box is at the Saunalahti company.)
Ah, the Germans: Masters of Convoluted Simplification. — [link|http://www.thetruthaboutcars.com/?p=1603|Jehovah]
|
Post #275,493
12/11/06 4:29:50 PM
|
The ultimate clueless non-programmer wannabe approach
Jesus FFING Christ!
You would ask for a VB macro to handle that type of processing to avoid a 5 minute ActiveState Perl download and install.
pfft!
Write it yourself.
|
Post #275,548
12/12/06 8:25:36 AM
|
Thanks a lot... (new thread)
Created as new thread #275547 titled [link|/forums/render/content/show?contentid=275547|Thanks a lot...]
[link|mailto:MyUserId@MyISP.CountryCode|Christian R. Conrad] (I live in Finland, and my e-mail in-box is at the Saunalahti company.)
Ah, the Germans: Masters of Convoluted Simplification. — [link|http://www.thetruthaboutcars.com/?p=1603|Jehovah]
|
Post #275,495
12/11/06 4:32:43 PM
12/12/06 9:13:09 PM
|
Well, in Squeak it would look something like
\ndoc := XMLDOMParser parseDocumentFrom: (FileDirectory current fileNamed: 'file.xml').\ndoc tagsNamed: 'attr' do:\n[:each |\n each contentsDo:\n [:t | t isText ifTrue: [t string: (((t string asLowercase split: '_') collect: [:s | s capitalized]) join: '_') ]]\n].\n(FileDirectory current forceNewFileNamed: 'file.xml') nextPutAll: (doc asString); close.\n Edit: fixed formatting
[link|http://www.blackbagops.net|Black Bag Operations Log]
[link|http://www.objectiveclips.com|Artificial Intelligence]
[link|http://www.badpage.info/seaside/html|Scrutinizer]
|
Post #275,499
12/11/06 4:42:57 PM
|
UltraEdit will do it.
I cut and pasted your example text in my copy of UltraEdit 9.00a: <someTag><attr ibute="bl-ah">MY_STRING_VALUE</attr> highlighted it, then did: Format -> Capitalize and it changed the text to: <Sometag><Attr Ibute="Bl-Ah">My_String_Value</Attr>. Is that close enough? I'm sure with the various searching options, and the ability to record macros, something could be cobbled together relatively quickly that you could save as a macro. It's pretty easy. [link|http://www.ultraedit.com/index.php?name=Downloads&d_op=viewdownload&cid=1|UltraEdit] is shareware - that link is to the 45 day trial page of UE 12.20a. There are probably free editors that will do the same thing, and be simpler to set up than a programming enviroment like perl or Python. HTH a bit. Cheers, Scott.
|
Post #275,502
12/11/06 4:57:24 PM
|
at risk of a war, do this
[link|http://math.claremontmckenna.edu/ALee/emacs/emacs.html|http://math.claremon.../emacs/emacs.html] thanx, bill
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 51 years. meep
reach me at [link|mailto:bill.oxley@cox.net|mailto:bill.oxley@cox.net]
|
Post #275,504
12/11/06 6:09:09 PM
|
alt-C, bay-bee.
Add a keyboard macro in the mix, and you're good to go. ;-)
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,506
12/11/06 6:48:22 PM
|
Go ahead
Write the lisp code the parse out particular tags. And explain it to him.
NOT YOU SCOTT!
|
Post #275,510
12/11/06 7:37:23 PM
|
get vi'ed :-) I dont use that shite
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 51 years. meep
reach me at [link|mailto:bill.oxley@cox.net|mailto:bill.oxley@cox.net]
|
Post #275,515
12/11/06 9:02:37 PM
|
Who the fsck writes LISP to use Emacs?
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,516
12/11/06 9:21:40 PM
|
Ok, fine.
Please show your solution in emacs.
|
Post #275,534
12/12/06 12:16:44 AM
|
I need more of the problem specifics
But it would be something along the lines of this keyboard macro:
^( ^s <name_of_tag ^f ^space ^s </name_of_tag> alt-b alt-b alt-b ^b ^b esc-x capitalize-region ^)
Then run the keyboard macro as many times as you need to. Basically it says, "find the next instance of the tag, mark everything in between the tag and the close tag as the region, then capitalize it".
It's a lot quicker to actually make the macro than it is to type it out, since you just do the editing commands you want to record. Probably 10-20 seconds to make the macro, then however long it takes to process the file.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,541
12/12/06 6:54:49 AM
|
Hope it's a single file
Initial post a "a file full of shtuff" so no need to load and save a bunch.
|
Post #275,553
12/12/06 10:21:34 AM
|
As always, use the right tool for the job.
For the majority of my text munging needs, emacs keyboard macros are capable, fast and easy.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,565
12/12/06 1:47:49 PM
|
Bunch of text mungers
its xml - thus a serialized object model.
Easier and more reliable to work on the dom I think.
But go ahead and live in your flat little world.
[link|http://www.blackbagops.net|Black Bag Operations Log]
[link|http://www.objectiveclips.com|Artificial Intelligence]
[link|http://www.badpage.info/seaside/html|Scrutinizer]
|
Post #275,569
12/12/06 2:25:35 PM
|
Er, come again?
20 seconds of work to do a one-off, vs. thinking and writing a program to do it the "correct" way. And what's the point of creating an object graph for the entire thing when he wants to change one tag's contents only?
I get work done. I don't worry too much about how I get it done unless it actually matters.
"flat little world"... Man, talk about your insults out of nowhere.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,586
12/12/06 6:26:07 PM
|
thats our todd, no point manipulating some text
when you can write a hello world example only using 11MB's of libraries and manipulating some text. thanx, bill
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 51 years. meep
reach me at [link|mailto:bill.oxley@cox.net|mailto:bill.oxley@cox.net]
|
Post #275,609
12/12/06 10:18:52 PM
|
Probably smaller than emacs, though :-P
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,596
12/12/06 9:08:52 PM
12/12/06 9:15:23 PM
|
Eh? I did it in 3 lines.
Anyhow, I find it easier to modify data structures than to fiddle text- which is error prone. When the text represents a data structure, like source code or xml, modifying the parse tree is more reliable and, I think, easier.
Anyhow, you're taking me way too seriously. :-)
[link|http://www.blackbagops.net|Black Bag Operations Log]
[link|http://www.objectiveclips.com|Artificial Intelligence]
[link|http://www.badpage.info/seaside/html|Scrutinizer]
|
Post #275,624
12/12/06 11:12:08 PM
|
Re: Eh? I did it in 3 lines.
If I were going to do it more than once, sure. Otherwise it's a waste of time. Writing a keyboard macro is simple and quick, much quicker than even your 3 lines of code.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,585
12/12/06 6:24:36 PM
|
emacs is xml?
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 51 years. meep
reach me at [link|mailto:bill.oxley@cox.net|mailto:bill.oxley@cox.net]
|
Post #275,535
12/12/06 12:24:14 AM
|
Re: Ok, fine.
The following macro:
;; Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel. ;; Original keys: C-s <attr 2*M-f 2*C-f C-SPC C-s </att 5*C-b ESC xcapital TAB reg TAB RET
Command: last-kbd-macro Key: none
Macro:
C-s\t\t\t;; isearch-forward <attr\t\t\t;; self-insert-command * 5 2*M-f\t\t\t;; forward-word 2*C-f\t\t\t;; forward-char C-SPC\t\t\t;; set-mark-command C-s\t\t\t;; isearch-forward </att\t\t\t;; self-insert-command * 5 5*C-b\t\t\t;; backward-char ESC xcapital\t\t;; self-insert-command * 4 TAB\t\t\t;; lisp-indent-line reg\t\t\t;; self-insert-command * 3 TAB\t\t\t;; lisp-indent-line RET\t\t\t;; newline
Used on the following:
asdsgas<attr ibute="foo">DINGLE_BERRIES</attr>jlj;lj;l <attr ibute="foo">DINGLE_BERRIES</attr><moo>on you</moo> <attr ibute="foo">DINGLE_BERRIES</attr><barry>likes herrings</barry> <attr ibute="foo">DINGLE_BERRIES</attr>
Produces:
asdsgas<attr ibute="foo">Dingle_Berries</attr> jlj;lj;l<attr ibute="foo">Dingle_Berries</attr><moo>on you</moo> <attr ibute="foo">Dingle_Berries</attr> <barry>likes herrings</barry> <attr ibute="foo">Dingle_Berries</attr>
Like I said, the exact form of the macro is going to depend on the specific data.
The macro above is suitable for pasting into ^x^k^xe, incidentally. ;-)
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #275,549
12/12/06 8:38:28 AM
|
Thanks, Scotts.
Yeah, Neo, I might even have tried vi or emacs, if I hadn't happened to have pretty much the same capabilities installed already (as can be seen in my reply to Barry's charming retort.)
And yeah, CollieKat, from your description the text editor you recommended seems to be pretty much as powerful as the one I use... i.e, *almost* powerful enough to do it! :-)
Thanks anyway, both of ya.
Really.
[link|mailto:MyUserId@MyISP.CountryCode|Christian R. Conrad] (I live in Finland, and my e-mail in-box is at the Saunalahti company.)
Ah, the Germans: Masters of Convoluted Simplification. — [link|http://www.thetruthaboutcars.com/?p=1603|Jehovah]
|