使用Perl单行文本,从文件中提取列:类似Unix的切 [英] Extracting columns from text file using Perl one-liner: similar to Unix cut
本文介绍了使用Perl单行文本,从文件中提取列:类似Unix的切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Windows,我想用Perl,Python和批次等一行程序从文本文件中提取某些列。
I'm using Windows, and I would like to extract certain columns from a text file using a Perl, Python, batch etc. one-liner.
在Unix上我可以这样做:
On Unix I could do this:
cut -d " " -f 1-3 <my file>
我怎么能这样做在Windows?
How can I do this on Windows?
推荐答案
下面是一个Perl单行打印文件的第一个3空格分隔列。这可以在Windows(或Unix)上运行。请参阅 perlrun 。
Here is a Perl one-liner to print the first 3 whitespace-delimited columns of a file. This can be run on Windows (or Unix). Refer to perlrun.
perl -ane "print qq(@F[0..2]\n)" file.txt
这篇关于使用Perl单行文本,从文件中提取列:类似Unix的切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文