【问题标题】:Control if a new file incoming in a folder with "comm"使用“comm”控制文件夹中是否有新文件传入
【发布时间】:2014-07-11 07:19:46
【问题描述】:

我在无限循环中使用 comm 来查看文件夹中是否有新文件传入,但我与 2 个文件没有区别,但例如,如果 incominig 文件“a”我在输出中查看:

a a.out a.txt b.txt test.cpp testshell.sh
    a.out a.txt b.txt test.cpp testshell.sh

我的代码是这样的:

#! /bin/ksh
ls1=$(ls);
echo $ls1 > a.txt;

 while [[ 1 > 0 ]] ; do
    ls2=$(ls);
    echo $ls2 > b.txt;
    #cat b.txt;
    #sort b.txt > b.txt;
    #diff -u a.txt b.txt;
    #diff -a --suppress-common-lines -y a.txt b.txt
    comm -3 a.txt b.txt;
    printf "\n";
    ls1=$ls2;
    echo $ls1 > a.txt;
    #cat a.txt;
    #sleep 2;
    #sort a.txt > a.txt;
 done

谢谢

【问题讨论】:

  • 当您将变量回显到文件中时,它们需要被双引号以保留换行符 - 例如echo "$ls1" > a.txt

标签: shell command-line ksh


【解决方案1】:
#! /bin/ksh

set -vx

PreCycle="$( ls -1 )"

while true
 do
   ThisCycle="$( ls -1 )"

   echo "${PreCycle}${ThisCycle}" | uniq

   PreCycle="${ThisCycle}"

   sleep 10
 done

给出添加和删除的区别,但不使用文件。可以直接以相同的方式提供新文件,但 uniq -f 1 在以 + 和 - 为前缀的列表中使用时失败(不明白为什么),具体取决于来源

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    相关资源
    最近更新 更多