编辑/分割/保存数据在文本文件中

发布于 2024-12-08 21:12:38 字数 1737 浏览 1 评论 0原文

我有一个名为 playlist.pls 的文本文件,它是动态创建的,在该文本文件中我有数千行,如下所示:

File000001=/home/ubu32sc/Documents/octave/pre/wavefn_0001.wav 
File000002=/home/ubu32sc/Documents/octave/pre/wavefn_0002.wav 
File000003=/home/ubu32sc/Documents/octave/pre/wavefn_0003.wav 
File000004=/home/ubu32sc/Documents/octave/pre/wavefn_0004.wav 
File000005=/home/ubu32sc/Documents/octave/pre/wavefn_0005.wav 
File000006=/home/ubu32sc/Documents/octave/pre/wavefn_0006.wav 
File000007=/home/ubu32sc/Documents/octave/pre/wavefn_0007.wav 
File000008=/home/ubu32sc/Documents/octave/pre/wavefn_0008.wav 
File000009=/home/ubu32sc/Documents/octave/pre/wavefn_0009.wav 
File000010=/home/ubu32sc/Documents/octave/pre/wavefn_0010.wav etc...

我需要将文本文件中的数据拆分为几个不同的文件。 示例:

The play1.pls file would contain:
File000001=/home/ubu32sc/Documents/octave/pre/wavefn_0001.wav 
File000002=/home/ubu32sc/Documents/octave/pre/wavefn_0002.wav 
File000003=/home/ubu32sc/Documents/octave/pre/wavefn_0003.wav 

The play2.pls file would contain:
File000004=/home/ubu32sc/Documents/octave/pre/wavefn_0004.wav 
File000005=/home/ubu32sc/Documents/octave/pre/wavefn_0005.wav 
File000006=/home/ubu32sc/Documents/octave/pre/wavefn_0006.wav 

The play3.pls file would contain:
File000007=/home/ubu32sc/Documents/octave/pre/wavefn_0007.wav 
File000008=/home/ubu32sc/Documents/octave/pre/wavefn_0008.wav 
File000009=/home/ubu32sc/Documents/octave/pre/wavefn_0009.wav 

The play4.pls file would contain:
File000010=/home/ubu32sc/Documents/octave/pre/wavefn_0010.wav etc...

执行此操作的最佳方法是什么我正在考虑使用 Octave/Matlab 来执行此操作,但我认为在包含数十数千行的文本文件上运行 for 循环会过度消耗和资源密集型。 grep 或 perl 是否适合使用,或者我应该使用其他类型的程序?如果是这样我该怎么做呢?

我正在使用 Ubuntu 32 10.04 6 gig 内存 谢谢

I have a text file called playlist.pls which is dynamically created, and in the text file I have thousands of lines that look like this:

File000001=/home/ubu32sc/Documents/octave/pre/wavefn_0001.wav 
File000002=/home/ubu32sc/Documents/octave/pre/wavefn_0002.wav 
File000003=/home/ubu32sc/Documents/octave/pre/wavefn_0003.wav 
File000004=/home/ubu32sc/Documents/octave/pre/wavefn_0004.wav 
File000005=/home/ubu32sc/Documents/octave/pre/wavefn_0005.wav 
File000006=/home/ubu32sc/Documents/octave/pre/wavefn_0006.wav 
File000007=/home/ubu32sc/Documents/octave/pre/wavefn_0007.wav 
File000008=/home/ubu32sc/Documents/octave/pre/wavefn_0008.wav 
File000009=/home/ubu32sc/Documents/octave/pre/wavefn_0009.wav 
File000010=/home/ubu32sc/Documents/octave/pre/wavefn_0010.wav etc...

I need to have the data in the text file split into several different files.
example:

The play1.pls file would contain:
File000001=/home/ubu32sc/Documents/octave/pre/wavefn_0001.wav 
File000002=/home/ubu32sc/Documents/octave/pre/wavefn_0002.wav 
File000003=/home/ubu32sc/Documents/octave/pre/wavefn_0003.wav 

The play2.pls file would contain:
File000004=/home/ubu32sc/Documents/octave/pre/wavefn_0004.wav 
File000005=/home/ubu32sc/Documents/octave/pre/wavefn_0005.wav 
File000006=/home/ubu32sc/Documents/octave/pre/wavefn_0006.wav 

The play3.pls file would contain:
File000007=/home/ubu32sc/Documents/octave/pre/wavefn_0007.wav 
File000008=/home/ubu32sc/Documents/octave/pre/wavefn_0008.wav 
File000009=/home/ubu32sc/Documents/octave/pre/wavefn_0009.wav 

The play4.pls file would contain:
File000010=/home/ubu32sc/Documents/octave/pre/wavefn_0010.wav etc...

What's the best way to go about doing this I was thinking about using octave/matlab to do this but I think this would be over kill and resource intensive to run a for loop on a text file with 10's of thousands of lines. Is grep or perl the proper thing to use and or should I use another type of program? and if so how could I do this with it?

I'm using Ubuntu 32 10.04 6 gig ram
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-12-15 21:12:38

正如您所提到的,如果您只想将一个文本文件拆分为多个文件,Matlab / Octave 似乎有点矫枉过正。

有一千种方法可以做到这一点(特别是在 UNIX 系统上),所以只需选择你的方法即可。

一种可能性是使用 split是这样的:

split --lines=3 file prefix

As you mentionned it, Matlab / Octave seems to be an overkill if you just want to split a text file into multiple files.

There are a thousand ways to do this (espcially on a unix system) so just pick yours.

One of the possibilities is to use split which goes like this:

split --lines=3 file prefix
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文