A list of csv files in directory need to be validated. Each column should pass its own validation; thus
A list of csv files in directory need to be validated. Each column should pass its own validation; thus $1 is first coulmn and it shouldn't be null and so on...
需要验证目录中的csv文件列表。每列应通过自己的验证;因此$ 1是第一个coulmn,它不应该是null等等......
After the csv file passed each validation for each column, it is considered a good file. Now how do I do go about extracting these good files so I can ftp them to another location?
在csv文件通过每列的每个验证之后,它被认为是一个好文件。现在我该怎么做才能提取这些好文件,以便将它们ftp到另一个位置?
Should I just ftp each file after each validation? (Too much time?)
我应该在每次验证后ftp每个文件吗? (太多时间?)
Create a list of names of the good files and pass it into an array so i can iterate through the array later to pass it to ftp?
创建一个好文件名称列表并将其传递给一个数组,以便我可以稍后遍历该数组以将其传递给ftp?
Here is my attempt so far.
这是我到目前为止的尝试。
#!/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
1 个解决方案
#1
0
Exit 1 from awk if check fails. Use if statement to transfer file when awk succeed.
如果检查失败,则从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
is first coulmn and it shouldn't be null and so on...A list of csv files in directory need to be val