【问题标题】:grep and find not working in shell scriptgrep 并发现在 shell 脚本中不起作用
【发布时间】:2017-05-11 09:25:00
【问题描述】:

我正在尝试通过 shell 脚本从存储在目录中的一组文件中 grep 特定模式。然而,脚本扫描文件,但它没有给我结果。我有 5 个文件,格式为 finishing with status COMPLETE

这是代码,请您帮忙解决问题

#!/bin/bash
dt=$(date --d='7 day ago' +'%Y%m%d')
countT=$("find /home/arun/file_status -type f  -name "product_feed_*stock*_${dt}*.out"  -exec grep "finishing with status COMPLETE" {} \;" | wc -l)
echo $countT
if [ $countT -eq 5 ]
then
   echo "Hello"
else
   echo "Hai"
fi

以下是错误:

find /home/arun/file_status -type f -name product_feed_stock_20170504*.out -exec grep Finishing: No such file or directory 0 Hai

【问题讨论】:

  • 下面是错误 find /home/arun/file_status -type f -name product_feed_stock_20170504*.out -exec grep Finishing: No such file or directory 0 Hai

标签: linux shell grep find


【解决方案1】:

需要删除 find 命令中的引号。

#!/bin/bash

dt=$(date --d='7 day ago' +'%Y%m%d') 

countT=$(find /home/arun/file_status -type f -name "product_feed_stock_${dt}*.out" -exec grep "finishing with status COMPLETE" {} \;| wc -l) 

echo $countT 
if [ $countT -eq 5 ] 
then 
  echo "Hello" 
else 
  echo "Hai" 
fi

【讨论】:

    猜你喜欢
    • 2013-11-01
    • 1970-01-01
    • 2023-03-18
    • 2021-10-04
    • 2017-06-21
    • 2013-12-03
    • 2023-02-05
    • 2011-10-27
    相关资源
    最近更新 更多