I finally found some script and simply modifided it to fit the purpose. Thanks stefanwagner for you help. The following code accepts the text file plus two numbers on command line.
usage:
java SelectLines my.txt 2 4
Output
line 2 of file
line 3 of file
line 4 of file
import java.io.*;
// Illustrate the LineNumberReader class.
class SelectLines {
public static void main(String[] args){
int n = 0;
int Line1;
int Line2;
// if statement to verify if the text file argument has been specified by the user
if(args.length > 0){
Line1 = Integer.parseInt(args[1]);
Line2 = Integer.parseInt(args[2]);
final int whichLine = 1;
for(n = 0; n < args.length; n++){
try {
selectLines(args[n], whichLine, Line1, Line2);
}
catch (Exception e) {
}
}
}
else{
// No file names were given.
System.out.println("Usage: "+"java SelectLines file ...");
}
}
public static void selectLines(String filename, int n, int L1, int L2)
throws FileNotFoundException, IOException {
LineNumberReader reader = new LineNumberReader(new FileReader(filename));
// Read the first line.
String line = reader.readLine();
while(line != null){
int lineNo = reader.getLineNumber();
// if((reader.getLineNumber() % n) == 0) {
//for(lineNo = 3; lineNo < 4; lineNo++){
if (((lineNo) >= L1) && ((lineNo) <= L2)) {
System.out.println(line);
}
line = reader.readLine();
}
reader.close();
}
}
Now i have another puzzle to solve
