-1

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.

  1. TRANSACTION_ID from 9093626660000000001 to 9093626660000010000. and
  2. VAULT_REPORT_NAME from VUpldr_QA_1Mb_Report00001 to VUpldr_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)
Suman Verma
  • 55
  • 1
  • 10
  • 3
    you can simply do it using any text editor's find in files and replace command e.g. notepad++ – Mustofa Rizwan Nov 02 '16 at 09:20
  • 1
    What I would do, is delete every file containing that text, and then writing that file with the new text if nothing is in there anyway. – grooveplex Nov 02 '16 at 09:29
  • 2
    If the files are **identical**, replace the text in one file, then delete the other 9999 files, and make 9999 copies of the first file. – Andreas Nov 02 '16 at 09:33
  • yeah...that would have been easy, if there was 1 or 10 files....i have 10k files.replacing in each file will be tasky if done manually – Suman Verma Nov 02 '16 at 10:17
  • i do not get..y have you given a negative to this question.Please help.i have a deadline to complete this today – Suman Verma Nov 02 '16 at 10:22
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tom Nov 02 '16 at 10:23
  • Do you really need to do it in Java? Do you need to do it only once? Simple bash script may be the perfect solution. – coolguy Nov 02 '16 at 10:23
  • no not necessary..simple bash script will work for me:) – Suman Verma Nov 02 '16 at 10:24

1 Answers1

0

There are many ways to do this. You can do it programmatically as well.

Simple solution will be using TextPad Here is a link for the same TextPad find and replace in files

Rishi Goel
  • 670
  • 4
  • 10