#] #] ********************* #] "$d_bin"'bank statement convert- develop.txt' # www.BillHowell.ca 15Aug2024 initial # view in text editor, using constant-width font (eg courier), tabWidth = 3 # 15Aug2024 test # echo 'Chequing,01926-5092937,5/17/2024,,"MISC PAYMENT","WCB ALBERTA ",1326.95,,' | sed 's|.*[,].*[,]\([0-9]*\)\/\([0-9]*\)\/\([0-9]*\)[,][,]["]\(.*\)["][,]["]\(.*\)["][,]\([-0-9.]*\)[,]\([-0-9.]*\)[,]\([-0-9.]*\)|\2-\1-\3\t\4, \5\t\6\t\7\t\8|' # echo '17-5-2024 MISC PAYMENT, WCB ALBERTA 1326.95 ' | sed 's|\x9|\n|g' # 22-Jul-2024 # if [ "-1" < 0 ]; then echo "negative"; else echo "positive"; fi # 12:26$ p_mthNamL="$d_bin"'monthNameL- mmm.txt' # 12:26$ sed -n '10p' "$p_mthNamL" # Oct # >> OK # 12:26$ numMth=10 # 12:30$ echo "$numMth" # 10 # 12:30$ sed -n "$numMth"p "$p_mthNamL" # Oct # >> OK # 12:55$ sed -n "$chr_apo""$numMth"p"$chr_apo" "$p_mthNamL" # May # OK # echo '-5' | head -1 # echo '-5' | sed 's|.\(.*\)|\1|' fNam=$( pth_get_fnmNoExt "$pCsv" ) pCsvTp="$d_temp"'pResult temp.txt' pTrans="$d_temp"'pTransaction temp.txt' pReslt="$d_work$fNam converted.txt" p_mthNamL="$d_bin"'monthNameL- mmm.txt' if [ -f "$pReslt" ]; then rm "$pReslt"; fi while IFS='' read -u 9 strTrans; do echo "$strTrans" | sed 's|\x9|\n|g' >"$pTrans" exec 8<"$pTrans" read -u 8 dater numDay=$( echo "$dater" | sed 's|\([0-9]*\)\-\([0-9]*\)\-\([0-9]*\)|\1|' ) numMth=$( echo "$dater" | sed 's|\([0-9]*\)\-\([0-9]*\)\-\([0-9]*\)|\2|' ) numYer=$( echo "$dater" | sed 's|\([0-9]*\)\-\([0-9]*\)\-\([0-9]*\)|\3|' ) # mthNam=$( sed -n "$chr_apo""$numMth"p"$chr_apo" "$p_mthNamL" ) # mthNam=$( sed -n '5p' "$p_mthNamL" ) mthNam=$( sed -n $numMth'p' "$p_mthNamL" ) read -u 8 comment read -u 8 debittt read -u 8 creditt read -u 8 balance debitSign=$( echo "$debittt" | sed 's|\(.\).*|\1|' ) #echo "debitSign= $debitSign" if [ "$debitSign" == '-' ]; then creditt=$( echo "$debittt" | sed 's|.\(.*\)|\1|' ) debittt='' else creditt='' fi #close 8 echo >>"$pReslt" "$numDay$mthNam$numYer $comment $debittt $creditt $balance" done 9<"$pCsvTp" pCsv_convertRBchq_pResult() { pCsv="$1" fNam=$( pth_get_fnmNoExt "$pCsv" ) d_work="$d_Midas"'Investments/RB/z_historic/' pCsvTp="$d_temp"'pCsv_convertRBchq_pResult csvTmp.txt' pTrans="$d_temp"'pCsv_convertRBchq_pResult transaction.txt' pRevrs="$d_temp$fNam reversed.txt" pReslt="$d_work$fNam converted.txt" # if [ -f "$pRevrs" ]; then rm "$pRevrs"; fi # if [ -f "$pReslt" ]; then rm "$pReslt"; fi sed 's|.*[,].*[,]\([0-9]*\)\/\([0-9]*\)\/\([0-9]*\)[,][,]["]\(.*\)["][,]["]\(.*\)["][,]\([-0-9.]*\)[,]\([-0-9.]*\)[,]\([-0-9.]*\)|\2-\1-\3\t\4, \5\t\6\t\7\t\8|' "$pCsv" >"$pCsvTp" # while IFS='' read -u 9 strTrans; do # echo "$strTrans" | sed 's|\x9|\n|g' >"$pTrans" # exec 8<"$pTrans" # read -u 8 dater # dayy=$( echo "$dater" | cut --bytes=1,2 ) # mnth=$( echo "$dater" | cut --bytes=4,5 ) # year=$( echo "$dater" | cut --bytes=7,8,9,10 ) # daterr="$year-$mnth-$dayy" # read -u 8 comment # read -u 8 creditt; creditt=$( echo "$creditt" | sed 's|\"||g' ) # read -u 8 balance; balance=$( echo "$balance" | sed 's|\"||g' ) # #close 8 # echo >>"$pRevrs" "$daterr $comment $creditt $balance" # done 9<"$pCsvTp" # tac "$pCsvTp" >"$pReslt" } # 15:29$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|.*\/\(.*\)\/.*\,.*|\1|' # 31 # >> OK! # 15:31$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|\(.*\)\/.*\/.*\,.*|\1|' # 1 # >> OK! # 15:38$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|.*\/.*\/\(.*\)\,.*\,.*\,.*\,.*|\1|' # 2019 # >> OK! # 16:32$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|\/|-|g;s|\(.*\)\-.*\-.*\,.*|\1|' # 1 # ~ # 16:32$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|\/|-|g;s|.*\-\(.*\)\-.*\,.*|\1|' # 31 # ~ # 16:33$ echo '1/31/2019,OTHER,Interest Paid,,4.89' | sed 's|\/|-|g;s|.*\-.*\-\(.*\)\,.*\,.*\,.*\,.*|\1|' # 2019 # >> OK for all three # $ echo '12/31/2019,OTHER,Interest Paid,,18.76' | sed 's|^[0-9]+\/\([0-9]+\)\/[0-9]+\,.*|\1|' PayPal fNam=$( pth_get_fnmNoExt "$pCsv" ) # echo "fNam = $fNam" d_work="$d_PayP" pTrans="$d_temp"'pTransaction temp.txt' pRevrs="$d_temp$fNam reversed.txt" pReslt="$d_work$fNam converted.txt" if [ -f "$pReslt" ]; then rm "$pReslt"; fi while IFS='' read -u 9 strTrans; do echo "$strTrans" | sed 's|^["]||;s|["]\,["]|,|g;s|["]$||;s|\,|\n|g' >"$pTrans" exec 8<"$pTrans" read -u 8 dater dayy=$( echo "$dater" | cut --bytes=1,2 ) mnth=$( echo "$dater" | cut --bytes=4,5 ) year=$( echo "$dater" | cut --bytes=7,8,9,10 ) daterr="$year-$mnth-$dayy" read -u 8 timer read -u 8 timeZone read -u 8 name read -u 8 type read -u 8 status read -u 8 currency read -u 8 amount read -u 8 receiptID read -u 8 balance #balance=$( echo "$balance" | sed 's|\"||g' ) #close 8 # don't need balance below : $chr_tab$balance # 30Apr2024 still a few transactions are screwed up if [[ -n "$name" ]]; then echo >>"$pReslt" "$daterr$chr_tab$name$chr_tab$amount" fi done 9<"$pCsv" # not used with PayPal : # tac "$pRevrs" >"$pReslt" } Conn1 pCsv_convertConn1_pResult() { pCsv="$1" fNam=$( pth_get_fnmNoExt "$pCsv" ) d_work="$dConn1" pTrans="$d_temp"'pTransaction temp.txt' pPaste="$d_temp"'pCsv_convertHSBC_pResult paste.txt' pRevrs="$d_temp$fNam reversed.txt" pReslt="$d_work$fNam converted.txt" if [ -f "$pPaste" ]; then rm "$pPaste" fi while IFS='' read -u 9 strTrans; do echo "$strTrans" | sed 's|\"\,\"|\n|g' >"$pTrans" exec 8<"$pTrans" read -u 8 account read -u 8 dater dayy=$( echo "$dater" | cut --bytes=5,6 ) mnth=$( echo "$dater" | cut --bytes=1,2,3 ) year=$( echo "$dater" | cut --bytes=9,10,11,12 ) daterr="$dayy-$mnth-$year" read -u 8 comment; comment=$( echo "$comment" | sed 's|\,$||' ) read -u 8 creditt; creditt=$( echo "$creditt" | sed 's|\$||' ) read -u 8 balance; balance=$( echo "$balance" | sed 's|\$\(.*\)\"|\1|' ) #close 8 echo >>"$pPaste" "$daterr $comment $creditt $balance" done 9<"$pCsv" # remove 1st line sed '1d' "$pPaste" | tac >"$pReslt" } fNam=$( pth_get_fnmNoExt "$pCsv" ) pCsvTp="$d_work"'pResult temp.txt' pTrans="$d_temp"'pTransaction temp.txt' pRevrs="$d_temp$fNam reversed.txt" pReslt="$d_work$fNam converted.txt" if [ -f "$pReslt" ]; then rm "$pReslt" fi #sed 's|\,["]*\([-0-9]*\)[,]*\([0-9.]*\)["]*\,["]*\([-0-9]*\)[,]*\([0-9.]*\)["]*|,\1\2,\3\4|' "$pCsv" >"$pCsvTp" while IFS='' read -u 9 strTrans; do echo "$strTrans" | sed 's|\,|\n|g' >"$pTrans" exec 8<"$pTrans" read -u 8 dater dayy=$( echo "$dater" | cut --bytes=1,2 ) mnth=$( echo "$dater" | cut --bytes=4,5 ) year=$( echo "$dater" | cut --bytes=7,8,9,10 ) daterr="$year-$mnth-$dayy" read -u 8 comment read -u 8 creditt; creditt=$( echo "$creditt" | sed 's|\"||g' ) read -u 8 balance; balance=$( echo "$balance" | sed 's|\"||g' ) #close 8 echo >>"$pRevrs" "$daterr $comment $creditt $balance" done 9<"$pCsvTp" tac "$pRevrs" >"$pReslt" }