I have two identical arrays, Noun and Noun1, and want to find and extract the line that contains the combination of words (parliamenr reviews). I want to use grep command in linux and I wrote the following code:
for(int i=0;i<noun.size();i++)
{
for(int j=0;j<noun1.size();j++)
{
String id1 = noun.get(i);
String id2 = noun1.get(j);
System.out.println(id1 +"\t"+id2);
Runtime rt = Runtime.getRuntime();
String[] cmd = { "/bin/sh", "-c", "grep \"id1 id2\" /local//wiki-pmi/*.txt"};
Process proc = rt.exec(cmd);
BufferedReader is = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
System.out.println(line);
}
}
}
fis.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
The problem is id1 and id2 do not refer to Arrays elements and the command search to find id1 and id2 in the text files instead. String[] cmd = { "/bin/sh", "-c", "grep \"id1 id2\" /local//wiki-pmi/*.txt"}; Could Anyone help me to change the code in a way that id1 and id1 refer to the array (noun and Nooun1) elements?