i'm not a java coder but need a commnad that will do
cut -d "/" -f1,2,3 MyFile
Any ideas?
i'm not a java coder but need a commnad that will do
cut -d "/" -f1,2,3 MyFile
Any ideas?
you can read the content of file in String then use subString
method.
Read the file. Split each line on /
and then print out the first three parts.
BufferedReader in = null;
try{
in = new BufferedReader(new FileReader("MyFile"));
String line = "" ;
while((line = in.readLine()) != null){
String[] fields = line.split("/");
System.out.printf("%s/%s/%s\n", fields[0], fields[1], fields[2]) ;
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
The main difference between Java coding and that script example is that they use different programming paradigm lest say that Java use Object Programing and that example can be assigned to declarative programing (You only express the logic, not the way to get the result) so no commands in Java.
So there is no command that You can use for this type of functionality.
There might be some package with this type of static procedure that works like that cut program. But still You will have to write a program to use it.
So if You would describe us the purpose of usage of this program (cut) )we could be able to provide You a good answer.