-1

How to connect to unix server and perform operation in java as we performed in unix screen. I wnat to execute this command "sed '1,2d;/affected/d;/^$/d;/------/d'" in java.

user2160534
  • 97
  • 1
  • 5
  • 12

1 Answers1

1

These are actually two questions.

How to execute a system command in Java. For that you can use Runtime.exec

Process p = Runtime.getRuntime().exec("sed '1,2d;/affected/d;/^$/d;/------/d' file.txt");
p.waitFor();

How to execute a command on a remote machine. This could be done with ssh

ssh user@example.com "sed '1,2d;/affected/d;/^$/d;/------/d' file.txt"

For that to work, you must have ssh installed, of course.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198