【问题标题】:unix shell: check file list in dir versus with list of files from a fileunix shell:检查目录中的文件列表与文件中的文件列表
【发布时间】:2013-03-30 12:32:12
【问题描述】:

我正在尝试编写一个 sh 脚本来检查文件中存储的文件扩展名列表中的所有文件是否位于特定目录中的某个位置。我正在做以下事情:

文件名看起来像 yyyymmdd.ext

hoff_list.lst 示例如下:

abc
dfg
hij
klm
xxx
...

我的脚本是:

#!/bin/ksh
PATH=$PATH:/usr/bin
_input="/exchange/hoff_list.lst"
hoffdate="20130328"
hsourcedir="/upload_data/"
while IFS=' \t\n' read -r line; do
echo "=$line=" #first problem there
hoff_name=$hsourcedir$hoffdate"."$line
  if test ! "$hoff_name"
     then echo "$hoff_name DOES exist"
     else echo "$hoff_name does NOT exist or is empty"
  fi
done < "$_input"

但它不会回复相关回复。如果文件 reqly 存在于 dir 中,它不会找到文件。 回声“=$line=”

重生

=abc
=dfg
...

预期时

=abc=
=dfg=
...

看起来有问题,但不知道如何处理。将感谢您的帮助...

【问题讨论】:

  • 如果您正在检查文件是否存在,我错过了 if [ -f $hoff_name ] 行。
  • try echo "=${line}=" – golimar 7 分钟前一样:=abc =dfg ...

标签: bash shell unix sh ksh


【解决方案1】:

文件/exchange/hoff_list.lst 具有CRLF 行结尾http://en.wikipedia.org/wiki/Newline

摆脱 CR。您可以尝试使用大多数 Linux 系统上可用的dos2unix 实用程序或参考http://en.wikipedia.org/wiki/Newline#Conversion_utilities

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多