python - Linux 中的配对文件

标签 python linux perl bash unix

我的目录中有大量文件及其其他语言的翻译。有 10 种不同语言的文件和 2 或 3 种不同语言的文件。文件的典型名称是 xx_xxxx_EN.html 及其翻译 xx_xxxx_IT.html 。我想提取一个包含文件名的 2 列 txt 文件。例如,对于英语 - 意大利语语言对: xx_xxxx_EN.html xx_xxxx_IT.html

最佳答案

#!/bin/bash 

ls -1 *EN.html | while IFS= read -r file
do 
    ls -1 ${file%_*}* | while IFS= read -r match
    do
    if [ "$file" != "$match" ]; then 
        echo "$file" "$match"
    fi 
    done 
done
<小时/>
$ ls *html 
01_DE.html 01_EN.html 01_ESP.html 01_IT.html 02_EN.html 02_IT.html 02_PL.html

$ ./pair.sh

01_EN.html 01_DE.html
01_EN.html 01_ESP.html
01_EN.html 01_IT.html
02_EN.html 02_IT.html
02_EN.html 02_PL.html

关于python - Linux 中的配对文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13961930/

相关文章:

python - Numpy直方图,如何在每个bin中取最大值

Python 导入类 Stack

linux - 根据不同的列值将多列合并为行

linux - Bash 脚本 : difference in minutes between two times

python - 如何比较 2 个 .txt 文件与 python 脚本?

windows - 如何从我的 Perl 程序中设置 cmd.exe 窗口的大小?

python - 如何将字符串中的元组转换为元组对象?

python - python和c++中类似的随机数生成但得到不同的输出

perl - 在 AWK 中调用 Perl 脚本

csv - 如何在 perl 中删除不可打印的字符 ^@