I have an example file, for example:
CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11
(
asdfa
)
CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11
(
asdfas
)
some other text in file
I want to convert this file to the following:
CREATE GLOBAL TEMPORARY TABLE 1
(
asdfa
)
CREATE GLOBAL TEMPORARY TABLE 2
(
asdfas
)
some other text in file
Thus, in each case, a number will be added to each TEMPORARY TABLE record.
So far I have the following groovy script:
int i = 0
new File ("C:\\Not_Modified").eachFile{file ->
println "File name: ${file.name}"
new File ("C:\\Not_Modified\\"+file.name).eachLine {line ->
if (line.indexOf("TEMPORARY TABLE")>0)
{
i++
}
}
println "There are ${i} occurences of TEMPORARY TABLE"
}
How can I change the text in a file? Should I write to another file?
btw, I have a directory in my script, because I will work on a large number of these types of files in the directory.
I should have chosen perl for this task, but wanted to give groovy a try.
josh
source
share