简体   繁体   English

如何使用Powershell从文本文件中提取字段

[英]how to yank out a field from a text file using Powershell

i'am trying to pull out a field from file and write the extracted field into a new file, could anybody please help me with this. 我正在尝试从文件中提取字段并将提取的字段写入新文件,请有人帮我解决这个问题。 i have the data in the file like below 我在文件中有如下数据

"","Processed","XXXXXX XX XXXX XXXX","Import","hgjgf XXXXXXXXXXX                LTD","XXX","sss,ggg.00","0x/xx/xxxx","Xrrrr XXXXXXXX","","XTH asdf XX XXXXXX
XXX000XXX
XXXXXX XXX OCEAN                                                                                           fsdgdhfjgh","WXXXXX","000XXX","X0ASDFXXX","XX","","","","X","","","X","","",""

Based on the input that you provided, if you had a file named foo.txt, then: 根据您提供的输入,如果您有一个名为foo.txt的文件,则:

Import-CSV C:\Path\To\foo.txt -Header (1..25) | Select-Object '4', '6', '8'

Would give you the 4th, 6th, and 8th fields. 将为您提供第4,第6和第8个字段。 You could of course use much more descriptive headers and if the file had headers in the first row you could use those without specifying your own. 您当然可以使用更多的描述性标题,并且如果文件的第一行包含标题,则可以使用这些标题而无需指定自己的标题。

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

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