Created
March 25, 2020 14:26
-
-
Save lululau/ddb77a61ba6e7f0158331474bbaf7c1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
for i in *.txt; do | |
echo '------------------------------------------------------' | |
base_name=${i%.txt} | |
contract_no=$(cat $i | iconv -c -f UTF-16LE | grep -o '合同 [0-9]*') | |
contract_no=${contract_no#* } | |
customer_name=$(cat $i | iconv -c -f UTF-16LE | grep -o '尊敬的 [^ ]*' ) | |
customer_name=${customer_name#* } | |
customer_name=$(echo -n "$customer_name" | ruby -pe 'gsub(/[^\u4E00-\u9FA5]/, "?")') | |
if [ -z "$contract_no" ] || [ -z "$customer_name" ]; then | |
echo "contract_no or customer_name not found, contract_no: $contract_no, customer_name: $customer_name" | |
continue | |
fi | |
account_no=$(grep -F "$contract_no" number-mapping.csv | cut -d, -f1) | |
if [ -n "$account_no" ]; then | |
echo "contract_no: $contract_no" | |
echo "customer_name: $customer_name" | |
echo "account_no: $account_no" | |
echo cp "$base_name.pdf" "$HOME/Desktop/11/${account_no}-${customer_name}-债转通知.pdf" | |
# cp "$base_name.pdf" "$HOME/Desktop/11/${account_no}-${customer_name}-债转通知.pdf" | |
else | |
echo "Mapping not found: $contract_no" | |
fi | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment