comm命令从file1 file2获取公共数据

时间:2015-07-20 19:41:23

标签: php linux shell

我想获取file1和file2中的公共数据。

<?php 
    $cmd="comm -12 <(sort /Source/20-07-2015/file1 | uniq) <(sort /Source/20-07-2015/file2 | uniq) > /20-07-2015/commondata_20072015-248932-ac.csv";
    $result =exec($cmd);
 ?>

但是上面的代码引发了错误:

sh: -c: line 0: syntax error near unexpected token `('

1 个答案:

答案 0 :(得分:0)

PHP exec()使用shsh不支持<(...)

最简单的解决方法(来自知道sh / bash而不是PHP的人)是让sh调用bash来运行您的命令:

$cmd="bash -c 'comm -12 <(sort /Source/20-07-2015/file1 | uniq) <(sort /Source/20-07-2015/file2 | uniq) > /20-07-2015/commondata_20072015-248932-ac.csv'";
相关问题