Iīm trying to make a java program that takes an argument as a variable. Then opens a file searches for a keyword and replaces the whole line with another.
for example as I would do it with the command sed -i "/OBSERVER/c OBSERVER 'argument' /DAY" hdu.tpl3
so I would look for the word OBSERVER in the file hdu.tpl3 and substitute the line with "OBSERVER 'argument' /DAY
This is the code a have and dosenīt change anything in the file
import java.io.*;
import java.util.regex.*;
public class FileTest {
public static void main(String[] args){
String name= "";
name = name + args[0];
String line= "sed -i";
line = line.concat(" \"/OBSERVER/c OBSERVER '");
line = line.concat(name);
line = line.concat("' /DAY \" hdu.tpl3");
String command = line;
System.out.println(command);
try{
Process process = Runtime.getRuntime().exec(command);
} catch (Exception e) {
System.out.println("Something went wrong.");
}
}
}