-3

我有这个脚本,我想从带有 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++;
    }       

  }   



  }

但它没有用,我用更多的方法来导航文件,我无法限制所需区域的读取!

4

1 回答 1

0

我不确切知道您面临的问题是什么。
但是我可以在您的代码中看到一个问题

while(scnr1.hasNextLine()){
        String line = scnr.nextLine();//this line is a problem
        if (lineNumber>numinf){
        System.out.println("line " + lineNumber + " :" + line);}
        lineNumber1++;
    }

将 scnr.nextLine() 更改为 scnr1.nextLine()
您的代码将被执行。

于 2013-07-18T00:47:44.957 回答