From: "David A. Black" Date: 2008-08-17T21:01:20+09:00 Subject: Re: String manipulation: cut, insert, column editing... --1926193751-1457662085-1218974670=:15121 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1457662085-1218974670=:15121" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1457662085-1218974670=:15121 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi Eric -- On Wed, 13 Aug 2008, Eric I. wrote: > On Aug 12, 3:09=A0pm, Toki Toki wrote: >> Hi all, >> >> Is it possible to use ruby like awk, sed or cut in unix to editing >> strings? >> >> Let say I have to write INSERT query like this: >> >> This is the first (1=B0) item. >> This is the second (2=B0) item. >> This is the third (3=B0) item. >> .. >> >> In one file I have the word-number (first, second, third) and in another >> file I have the real number (1=B0, 2=B0, 3=B0) of the item, both on each= line. > > Here's some Ruby code that may do what you're interested in: > > =3D=3D=3D=3D > > d1 =3D open("f1.txt") do |f| > f.readlines.map { |line| line.chomp } > end You can even skip the readlines and just map the IO handle: f.map {|line| line.chomp } David --=20 Rails training from David A. Black and Ruby Power and Light: * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates! --1926193751-1457662085-1218974670=:15121-- --1926193751-1457662085-1218974670=:15121--