I have a sample file like the following:
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 into following:
CREATE GLOBAL TEMPORARY TABLE 1
(
asdfa
)
CREATE GLOBAL TEMPORARY TABLE 2
(
asdfas
)
some other text in file
So basically every TEMPORARY TABLE occurrence will have number appended to it.
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 the file? should I be writing to a different file?
btw, I have directory in my script because I will be working on lot of these type of files in a directory.
I should have opted perl for this task but wanted to give groovy a try.