From: Robert Klemme Date: 2008-08-13T16:33:50+09:00 Subject: Re: String manipulation: cut, insert, column editing... 2008/8/12 Toki Toki : > Is it possible to use ruby like awk, sed or cut in unix to editing > strings? These are quite different tools but yes, you can use Ruby like them most of the time. Please also have a look at command line parameters of the Ruby interpreter (ruby -h). > Let say I have to write INSERT query like this: > > This is the first (1°) item. > This is the second (2°) item. > This is the third (3°) item. > ... This does not look like an SQL INSERT statement, what is it? > In one file I have the word-number (first, second, third) and in another > file I have the real number (1°, 2°, 3°) of the item, both on each line. Not sure what exactly you are trying to do. For the loading part here's another variant: h = {} File.open "f1.txt" do |io1| File.open "f2.txt" do |io2| io1.zip io2 do |k,v| h[k.chomp] = v.chomp end end end p h > Of course, I don't want to really write it, so how can I "edit" the > number of the item dinamically? I've tried with regex, but I haven't > found a solution... > > I think that with some text editors maybe it's possible to do that, but > I would like to know if with ruby the result can be achieved easier. Well, if you tell us what exactly you are trying to achieve. At least to me it's not fully clear. Kind regards robert -- use.inject do |as, often| as.you_can - without end