我有这个脚本,我想从带有 HDK 文本的行中提取行到每行带有 SDK 文本行的行
#! /bin/sh
# ==================================================================
# ______ __ _____
# /_ __/___ ____ ___ _________ _/ /_ /__ /
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / /
# / / / /_/ / / / / / / /__/ /_/ / /_ / /
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/
HDK
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
# and enterprise use with large-scale deployments.
# Credits:
# Google -> Couldn't survive without it
# Stackoverflow.com -> Community support
# SpringSource -> Specifically best-practices and seminars (Expert Series)
SDK
# Based On:
# http://www.springsource.com/files/uploads/tomcat/tomcatx-performance-tuning.pdf
http://www.springsource.com/files/u1/PerformanceTuningApacheTomcat-Part2.pdf
# http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf
请帮忙 !我试过
public class ScannerExample {
public static void main(String args[]) throws FileNotFoundException {
//creating File instance to reference text file in Java
File text = new File("E:\\file.txt");
//Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(text);
//Reading each line of file using Scanner class
int lineNumber = 1;
int lineNumber1 = 1;
int numinf = 1;
int numsup=1;
while(scnr.hasNextLine()){
String line = scnr.nextLine();
if (line.contains("HDK")){numinf=lineNumber;
System.out.println(numinf);
}
if (line.contains("SDK")){numsup=lineNumber;
System.out.println(numsup);}
lineNumber++;
}
Scanner scnr1 = new Scanner(text);
while(scnr1.hasNextLine()){
String line = scnr.nextLine();
if (lineNumber>numinf){
System.out.println("line " + lineNumber + " :" + line);}
lineNumber1++;
}
}
}
但它没有用,我用更多的方法来导航文件,我无法限制所需区域的读取!