简体   繁体   English

将数据关联到文本文件

[英]Associating data to text files

I need a good way to the following: 我需要一个很好的方法来做到以下几点:

I have several text files, I need to be able to associate to some lines other data 我有几个文本文件,我需要能够与某些行关联其他数据

Eg 例如

Text file: 文本文件:

Line1
Line2
...
...
Line98

Additional data: 附加数据:

Line1    |This is additional data
Line2    |associated with line1 till line2
...
...
Line98

I don't want to modify the text files, so I'm going to need to store this information in another file. 我不想修改文本文件,因此我需要将此信息存储在另一个文件中。 Notice that the text files might change, so keeping track of the number of the lines isn't a safe way to do what I need. 请注意,文本文件可能会更改,因此跟踪行数并不是执行我所需的安全方法。

Any suggestion? 有什么建议吗?

If you cannot change the text file, one solution is to copy the text file, and modify the copy with the additional information. 如果无法更改文本文件,一种解决方案是复制文本文件,并使用其他信息修改副本。 When someone modifies the original file, you can detect the changes, by noticing that not all the lines in the original file have information associated with it in your copy with the additional information. 当有人修改原始文件时,您可以通过注意到并非原始文件中的所有行在副本中都具有与之相关联的信息以及其他信息来检测更改。

But, really a better solution is to change the original file in some simple way that makes it easy to find the associated additional information. 但是,实际上,更好的解决方案是以某种简单的方式更改原始文件,从而可以轻松找到关联的其他信息。 Like: 喜欢:

Line1 [INFO-1]
Line2 [INFO-2]
...
...
Line98 [INFO-98]

And in your other file, you would have 在另一个文件中,

[INFO-1] Additional info associated with INFO-1 tag that
can continue on the next line if you want
[INFO-2] Additional info for INFO-2
...
[INFO-98] Additional info

Now, when someone changes the original file, a new line will not have the [INFO-#] tag, and changing a line with an existing [INFO-#] tag won't change the additional info associated with it. 现在,当某人更改原始文件时,新行将没有[INFO-#]标签,并且更改具有现有[INFO-#]标签的行不会更改与之关联的其他信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM