运行环境:centos6.5 eclipse
可以借鉴转码译文分析
public static void insert(){
String pathshell="/home/wjx/spider/baidu/java.sh";//String cmd="sort /home/wjx/spider/baidu/SearchUrl_CSDN.txt | uniq >/home/wjx/spider/baidu/SearchUrl_CSDN_b.txt;sort /home/wjx/spider/baidu/SearchUrl_OSchina.txt | uniq >/home/wjx/spider/baidu/SearchUrl_OSchina_b.txt";
Process ps;
try {
//ps = Runtime.getRuntime().exec(new String[]{"sh","-c",cmd});
ps = Runtime.getRuntime().exec(pathshell);
ps.waitFor();
String path = "/home/wjx/spider/baidu/";
File f = new File(path);
String[] names = f.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.indexOf(".txt") != -1;// 等于-1,表示不存在
}
});
for (String str : names) {
if (str.endsWith("_b.txt"))
//insert_b(path + str);
if (str.endsWith("_v.txt"))
;
}} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
"/home/wjx/spider/baidu/java.sh" 中的shell脚本:
sort /home/wjx/spider/baidu/SearchUrl_CSDN.txt | uniq >/home/wjx/spider/baidu/SearchUrl_CSDN_b.txt
sort /home/wjx/spider/baidu/SearchUrl_OSchina.txt | uniq >/home/wjx/spider/baidu/SearchUrl_OSchina_b.txt