* Khurram (khabibiuf / hotmail.com) wrote: > Hi all, > > I'm trying to modify a file that has tab delimited fields. I want to > modify the 4th field within each row. I can get to the field I want > by using the "split" function operating on \t delimiter... but this > function returns an array right? It doesn't return a pointer to the > fields? > > So if it doesn't return a pointer then how can I modify the field > within the file easily? > > a = File.open("blah.txt") > f = (a.gets).split(/\t/) > f[4] = f[4] + "blah" > .... what do I do after this? How can I write the value back out to > the file? You should be looking to write out the file again with modifications made, so for example, iterate over each line in the file, change the ones you wish to, and write the line back out to a new file, or read in the whole file into an array (see IO.readlines), modify the array, and then write the array of lines back out to the original file. Tom. -- .^. .-------------------------------------------------------. /V\ | Tom Gilbert, London, England | http://linuxbrit.co.uk | /( )\ | Open Source/UNIX consultant | tom / linuxbrit.co.uk | ^^-^^ `-------------------------------------------------------'