EDIT: I have 10,000 identical files with below text in it.
TRANSACTION_ID=9093626660000000001,VAULT_REPORT_NAME=VUpldr_QA_1Mb_Report00001,DIMENSION=REGION:Europe;LOB:All LOB;CATEGORY:RO Reporting;CUSTOMER:All Customer;FREQUENCY:Daily;REPORT AUDIENCE:Apple RO Reporting;REPORT SUBSCRIPTION:Apple RO Reporting
My requirement is to replace as below in 10 k files.
- TRANSACTION_ID from
9093626660000000001
to9093626660000010000
. and - VAULT_REPORT_NAME from
VUpldr_QA_1Mb_Report00001
toVUpldr_QA_1Mb_Report10000
So my output files contents would be
file 1st:
TRANSACTION_ID=9093626660000000001,VAULT_REPORT_NAME=VUpldr_QA_1Mb_Report00001,DIMENSION=REGION:Europe;LOB:All LOB;CATEGORY:RO Reporting;CUSTOMER:All Customer;FREQUENCY:Daily;REPORT AUDIENCE:Apple RO Reporting;REPORT SUBSCRIPTION:Apple RO Reporting
file 2nd:
TRANSACTION_ID=9093626660000000002,VAULT_REPORT_NAME=VUpldr_QA_1Mb_Report00002,DIMENSION=REGION:Europe;LOB:All LOB;CATEGORY:RO Reporting;CUSTOMER:All Customer;FREQUENCY:Daily;REPORT AUDIENCE:Apple RO Reporting;REPORT SUBSCRIPTION:Apple RO Reporting
file 10000th:
TRANSACTION_ID=9093626660000010000,VAULT_REPORT_NAME=VUpldr_QA_1Mb_Report10000,DIMENSION=REGION:Europe;LOB:All LOB;CATEGORY:RO Reporting;CUSTOMER:All Customer;FREQUENCY:Daily;REPORT AUDIENCE:Apple RO Reporting;REPORT SUBSCRIPTION:Apple RO Reporting
I wrote below code but that isn't working:
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class mdScript {
public static void main(String[] args) throws IOException {
for (int i=1;i<=10000;i++){
StringBuffer pathVarBuf = new StringBuffer();
pathVarBuf.append("/Users/564169/Desktop/Vault_Testing/vUpldr/MD/1MbReport");
pathVarBuf.append(i);
pathVarBuf.append(".md");
//System.out.println(pathVarBuf);
Path path = Paths.get(pathVarBuf.toString());
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll("VUpldr_QA_1Mb_Report00001", "RVUpldr_QA_1Mb_Report"+i);
int id=999900001; // (Transaction id in the org MD file is 90)
id = id+i;
content = content.replaceAll("999900001", Integer.toString(id));
Files.write(path, content.getBytes(charset));
System.out.println(content);
}
}
}
I am getting below error:
Exception in thread "main" java.lang.NullPointerException
at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:267)
at java.nio.file.Paths.get(Paths.java:84)
at mdScript.main(mdScript.java:22)