将两个文件夹中的相同命名文件连接成一个

时间:2012-08-20 14:46:12

标签: bash unix

我有两个包含数千个文档的文件夹。假设A和B是目录。AB包含文件a.x b.x,依此类推。当然,内容是不同的。所以我想追加a.x & a.x在其他文件夹中生成另一个a.x。此外,我需要从第二个文档中删除第一个令牌,如:

a.x in A:1 i go home
a.x in B:1 he goes home

我想生成新文档:

      1 i go home  he goes home. 

请给我一些脚本。

2 个答案:

答案 0 :(得分:1)

我愿意:

mkdir OUTPUT
cd A
for f in *
do
  join $f ../B/$f > ../OUTPUT/$f
done

答案 1 :(得分:0)

您可以使用for ... in循环和join(1)

来完成此操作
mkdir c # for storing the results
for file in $(ls a): do
    join "a/$file" "b/$file" >> "c/$file"
done