0
我有這個腳本將讀取將在目錄中的csv文件。不過我希望腳本它移動到第二列即用於驗證列的shell腳本
Name, City
Joe, Orlando
Sam, Copper Town
Mike, Atlanta
所以它必須首先檢查coulmn將其命名爲moveds在檢查前市之前驗證.csv文件的整個coulmn?我將如何更改以下腳本來迎合此?
# Read all files. no file have spaces in their names
for file in /source/*.csv ; do
# init two variables before processing a new file
FILESTATUS=GOOD
FIRSTROW=true
# process file 1 line a time, splitting the line by the
# Internal Field Sep ,
cat "${file}" | while IFS=, read field1 field2; do
# Skip first line, the header row
if [ "${FIRSTROW}" = "true" ]; then
FIRSTROW=FALSE
# skip processing of this line, continue with next record
continue;
fi
#different validations
if [[ "${field1}" = somestringprefix* ]]; then
${FILESTATUS}=BAD
# Stop inner loop
break
fi
somecheckonField2
done
if [ ${FILESTATUS} = "GOOD" ] ; then
mv ${file} /source/good
else
mv ${file} /source/bad
fi
done
感謝但上面的腳本,它迭代垂直檢查列中的每個字段,而不是水平這是傳統的評價 – 2015-02-09 16:45:07
它逐行驗證。但是如果一行無效,它會停止對該文件的進一步處理並返回'1' – hek2mgl 2015-02-09 16:48:08