linux - shell/linux 脚本仅选择某些文件到 FTP

标签 linux bash shell ftp

需要验证目录中的 csv 文件列表。每列都应该通过自己的验证;因此 $1 是第一个并且它不应该为 null 等等......

csv 文件通过每列的验证后,就被认为是一个好的文件。现在我该如何提取这些好的文件,以便将它们 ftp 到另一个位置?

  1. 每次验证后我是否应该只通过 ftp 传输每个文件? (时间太多?)

  2. 创建好文件的名称列表并将其传递到一个数组中,以便我稍后可以迭代该数组以将其传递到 ftp?

这是我迄今为止的尝试。

#!/bin/sh

for file in /source/*.csv

do
   awk -F',' '{
$date_regex = '~(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d~';

 if (length($1) == "")  
break
 if (length($2) == "") && (length($2) > 30)
break
 if (length($3) == "") && ($3 !~ /$date_regex/)
break
 if (length($4) == "") && (($4 != "S") || ($4 != "E")   
break
 if (length($5) == "") && ((length($5) < 9 || (length($5) > 11)))
break

}' file

    #whatever you need with "$file"
done

最佳答案

如果检查失败,则从 awk 中退出 1。当 awk 成功时使用 if 语句传输文件。

#!/bin/sh

    for file in /source/*.csv; do
       if awk -F',' '{
     # your multiple checks here.
     if (length($1) == "") && (length($2) == "") && (length($2) > 30) && ...)
           exit 1
    }' "$file"; then [scp or ftp command as you like]; fi       
    done

关于linux - shell/linux 脚本仅选择某些文件到 FTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28155831/

相关文章:

linux - 如何在 Linux 中创建文件监听器?

c++ - 有没有办法在 C 或 C++ 中嵌入 Sh/Bash session ?

python - 来自外部驱动器的 Subprocess.call()

linux - grep : Memory Exhausted on comparing two files to find the delta

c - 如何在 Linux 应用程序中获取有关以太网的统计信息?

linux - 在源代码级别是否有任何 linux 内核模块的模块依赖定义?

linux - dpkg -L package_name 如何工作?

python - 通过 shell 杀死进程而不杀死自身

linux - 在集群队列中执行 Fortran 时出现问题

linux - SED 删除带有扩展名的单词