PowerShell按文件1中的列对文件2进行排序

PowerShell按文件1中的列对文件2进行排序,powershell,Powershell,我有2个txt文件 File 1 File2 sql00003 test1.txt test1.txt sql00002 test3.txt test3.txt sql00001 test5.txt test5.txt 文件1需要按列1排序,然后文件2需要与文件1的顺序相同 (sorted by col2 of file1) test5.txt test3.txt test1.t

我有2个txt文件

File 1                        File2
sql00003 test1.txt            test1.txt 
sql00002 test3.txt            test3.txt 
sql00001 test5.txt            test5.txt
文件1需要按列1排序,然后文件2需要与文件1的顺序相同

(sorted by col2 of file1)
test5.txt
test3.txt
test1.txt

这可能与Powershell有关吗?

问题陈述有些奇怪,就像文件内容或排序规则中缺少一些关键信息一样

就我所理解的问题而言,为什么还要麻烦对第二个文件进行排序呢?根据您的数据,它包含第一个文件内容的子集。只需在排序后提取第一个文件的第二列

# Declare headers so file looks like CSV
$f = Import-Csv file1.txt -Delimiter " " -Header sql, file
# CSV is structured, so it can be sorted by column
$sorted = $f | sort -Property sql
# Extract only the file column and add its content to new file  
$sorted | select -ExpandProperty file | set-content file1b.txt

# Output    
cat file1b.txt
test5.txt
test3.txt
test1.txt

如果这不是您想要的,请在问题中添加更多内容。

这是可能的,但您需要提供一个更好的数据示例,以及您到目前为止尝试过的代码。文件的定义与您看到的一样文件1在第1-8列中有序号文件名在第10-18列文件2在第1列中有文件名我分了两个步骤:首先使用第1列到第8列gc对文件进行排序“C:\Users\Bruce\process.txt”| sort | get unique>“C:\Users\Bruce\sorted.process.txt”然后执行第二步文件2按正确顺序导入csv C:\Users\Bruce\sorted.process.txt | sort object Col2 |输出文件C:\Users\Bruce\Serena \-递归