我有这样的txt文件中来测试设备的数据表格机器。
标准化报告时间= 1550 9/22/14 卷筒扫描粘土 陈1陈2陈3陈4陈5陈6 空分(CCHi):75455。74464。75353。75539。75300。73303。 标志计数(C2CHi):75463。74462。75340。75537。75287。73283。 计数/T0 (TCHi):1.0061 0.9929 1.0047 1.0072 1.0040 0.9774 RS比率(RS2):1.0133 1.0014 0.9989 1.0021 1.0294 旗标比率(RFS2):1.0001 1.0003 1.0001 1.0003 1.0004 旗鼠/T0 (FSTR2):1.0001 1.0003 1.0001 1.0003 1.0004标准化报告时间= 1550 9/22/14 1层基WT F/A比0.7582净空气碳纳米管73044.5净旗碳纳米管 55379.7 BKGROUND 484.0 BW国旗50.196 DFRAC 0.1006 ZFRAC 0.0000 上升空气温度0.00卢氏空气温度0.00源温度0.00 RCVR温度0.00升头温度2616.71罗头温度 标准化报告时间= 1550 9/22/14 第一层水分 透射红外 增益:0 增益FCTR 1.0000 STDR 1.0000 RS 0.9907 RFS 1.0000 RFS0 1.0000 RS0 1.0000 参考文献75836.3 MES 76550.6 参考文献1.0112 MESRAT 1.0207标准化报告时间= 1550 9/22/14 第一层黏土 陈1陈2陈3陈4陈5陈6 空分(CCHi):75836。76551。75018。69494。74184。72229。 标志计数(C2CHi):75811。76521。75001。69469。74135。72195。 计数/T0 (TCHi):1.0112 1.0207 1.0002 0.9266 0.9891 0.9631 RS比率(RS2):0.9907 1.0109 1.0913 1.0223 1.0499 旗标比率(RFS2):1.0000 0.9999 1.0000 1.0003 1.0001 旗鼠/T0 (FSTR2):1.0000 0.9999 1.0000 1.0003 1.0001背景报告时间= 1551 9/22/14 原始库存基础WT BKG统计333.0背景报告时间= 1551 9/22/14 原料水分 透射红外 深色CNTS参考文献461。PHSE 2参3528。PHSE 3参10326。参考文献34457。 暗碳纳米管MES 474.PHSE 2 MES 3532PHSE 3 MES 10338。PHSE 4 MES 34499。 GAF1 1.0000 GAF2 1.0001
我希望能够将字符串拆分为双换行,然后在每个数据块的第二行上按机器名称对测试进行排序。
因此,它将只输出测试由卷轴扫描粘土,或第一层基础WT取决于你想要的测试。输出可能是这样的。
标准化报告时间= 1510 9/22/14 卷筒扫描粘土 陈1陈2陈3陈4陈5陈6 空分(CCHi):75455。74464。75353。75539。75300。73303。 标志计数(C2CHi):75463。74462。75340。75537。75287。73283。 计数/T0 (TCHi):1.0061 0.9929 1.0047 1.0072 1.0040 0.9774 RS比率(RS2):1.0133 1.0014 0.9989 1.0021 1.0294 旗标比率(RFS2):1.0001 1.0003 1.0001 1.0003 1.0004 旗鼠/T0 (FSTR2):1.0001 1.0003 1.0001 1.0003 1.0004标准化报告时间= 1525 9/22/14 卷筒扫描粘土 陈1陈2陈3陈4陈5陈6 空分(CCHi):72581。73115。75020。75437。74880。72770。 标志计数(C2CHi):72606。73125。75037。75463。74897。72798。 计数/T0 (TCHi):0.9677 0.9749 1.0003 1.0058 0.9984 0.9703 RS比率(RS2):0.9927 0.9675 0.9621 0.9693 0.9974 旗标比率(RFS2):1.0002 1.0001 1.0000 1.0001 1.0000 旗鼠/T0 (FSTR2):1.0002 1.0001 1.0000 1.0001 1.0000标准化报告时间= 1540 9/22/14 卷筒扫描粘土 陈1陈2陈3陈4陈5陈6 空分(CCHi):72386。73145。75112。75481。74953。72838。 标志计数(C2CHi):72462。73174。75132。75498。74976。72846。 计数/T0 (TCHi):0.9652 0.9753 1.0015 1.0064 0.9994 0.9712 RS比率(RS2):0.9896 0.9637 0.9590 0.9658 0.9938 旗标比率(RFS2):1.0007 1.0008 1.0008 1.0007 1.0009 旗鼠/T0 (FSTR2):1.0007 1.0008 1.0008 1.0007 1.0009
任何帮助都将不胜感激。
发布于 2014-12-04 16:17:48
我让步了,你想要打破几条线
Class Paragraph
Inherits List(Of String)
Public Property Line2 As String
If Me.Count >= 2 Then
Return Me(1)
End If
Return Null
End Property
End Class
要做到这一点,你需要代码,
Public Function FileBreaker(
path As String) As IEnumerable(Of Paragraph)
Dim emptyLine = False
Dim nextParagraph = New Paragraph()
For Each Dim line In File.ReadLines(path)
If String.IsNullOrEmpty(line) Then
If emptyLine Then
emptyLine = False
Yield nextParagraph
nextParagraph = New Paragraph()
Else
emptyLine = True
End If
Continue
End If
If emptyLine Then
nextParagraph.Add(String.Empty)
emptyLine = False
End If
nextParagraph.Add(line)
Next
End Function
你可以用来做这样的事,
Dim sortedParagraphs = FileBreaker("MyData.txt").OrderBy(Function(p) p.Line2)
发布于 2014-12-04 15:41:43
更新的代码以匹配所需的输出
注意:代码是用java编写的,因为初始标记是Java
。
试试这个:
public static void main(String[] args) throws IOException {
final Scanner scanner = new Scanner(new File("machines.txt"));
final String search="REEL SCAN CLAY";
String allMachines = "";
//read line by line, adding each line to a string delimited by ";" ignore empty line
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.equalsIgnoreCase("")) {
allMachines = allMachines + line + ";"; //machine attribute delimiter
} else {
allMachines = allMachines + line + "%"; //machine delimiter
}
}
scanner.close();
allMachines = allMachines.replace(";%", "%"); //no need for that extra ; and the end of a machine
final String[] machines = allMachines.split("%"); // identify all machines
for (final String machine : machines) {
final String[] machineAttributes = machine.split(";"); //split via the attribute delimiter
//extract attributes for each machine
//the one you want is the second so [1]
final String searchKey= machineAttributes[1];
if(searchKey.equalsIgnoreCase(search)){
//this machine contains the test you want. write all of it's attributes
//to another file or outputstream
for(int i=0;i<machineAttributes.length;i++){
//write machineAttributes[i] to a file, one on each line
}
}
}
}
https://stackoverflow.com/questions/27297401
复制相似问题