#] #] ********************* #] "$d_bin"'fileops notes.txt' # www.BillHowell.ca 26Feb2023 initial, took older notes from # "$d_SysMaint"'webSite/0_website bash notes.txt' - etc # view in text editor, using constant-width font (eg courier), tabWidth = 3 #48************************************************48 #24************************24 # Table of Contents, generate with : # $ grep "^#]" "$d_bin"'fileops notes.txt' | sed "s/^#\]/ /" # ********************* "$d_bin"'fileops notes.txt' 16Mar2024 povrL_pRgxP_replace(): in future, add options to pth file 15Mar2024 povrL_pRgxP_replace(): revamp arrays nested- test ndfs 15Mar2024 check rm [povr_pStrP_replace, povr_pRgxP_replace, povrL_rgxP_replace] 27Feb2024 change povrL_pStrP_replace because of bookmarks: '^#] ' comment, not `# 26Feb2024 fileops.sh add pth_get_ext() - get extension without fname from pth 24Feb2024 'pStrPAll_L change.txt' - are [^#, whitespace] lines ignred?? 16Feb2024 post changes, run dWeb_get_pHtmWebYesNonL 14Feb2024 fileops.sh: rm function pHtml_extract_pTOC(pHtml pTblOfCont) 13Feb2024 correct [set, use] * [dir, pth] names 05Feb2024 Segmentation fault - must be new code 20Jan2024 19Jan2024 dWeb_get_pWebPageL 12Nov2023 fix pOvrL_pStrP_pInsert_replace() ALL webPages 11Nov2023 fix pOvrL_pStrP_pInsert_replace() test[1, 5] 30Sep2023 z_historic 'webSite update.sh' 24Sep2023 webSite_getCheck_internalLinks() - remove sedExpr 17Sep2023 create initial povrL_pTypRgxT_replace family of functions 14Sep2023 now fixed: some are wrong!! after combining [bolPovEs, bolPstrEs] -> bolChrCd 14Sep2023 pOvrL_pStrP_replace - should either [en, de]code [neither, both] [pOvr, pStrP] 14Sep2023 now fixed: some are wrong!! after combining [bolPovEs, bolPstrEs] -> bolChrCd 14Sep2023 pOvrL_pStrP_replace - should either [en, de]code [neither, both] [pOvr, pStrP] +-----+ see "$d_bin"'0_test/fileops/povrL_pStrP_replace/0_povrL_pStrP_replace_test notes.txt' see "$d_bin"'0_test/fileops/povr_strP_replace/0_povr_strP_replace_test notes.txt' 31Jul2023 strSearch_strP_replace_test() - many examples 31Jul2023 pStrP_sedEsc_test() 31Jul2023 [str, povr] replace [strP, pStrP] in path[,L] - collection of functions povr_sedEsc() - escape ALL OR[sedEscSearch, sedEscApo] in povr 28Jul2023 create fileops.sh sedEscape() +-----+ 16Mar2023 readarray -t fndL611 <"$pinn", want a txtL from readarray - NOT an evaluation 15Mar2023 15Mar2023 pinn_getLinseq_povr() - extract a sequence of lines between [strt, endd] markers in pTxt 15Mar2023 pinn_sedFndGetPut_pout() 14Mar2023 povr_sedEach_sedAll() - transforms matching sequences of lines 01Mar2023 clean up file_ops.sh: povr_strP_replace() etc, tests for wrd povr_strP_replace - backs up povr, replaces strOld with strNew, backup flag 03Mar2023 develop "$d_bin"'port bash to python.sh' 02Mar2023 cp file_ops.sh to python, same function names 01Mar2023 more dirChanges, to make pths shorter 01Mar2023 search 'bash read syntax error near unexpected token `newline' 01Mar2023 pinn_pOld_pNew_replace() development, fixes 01Mar2023 search 'Linux bash read and what is the maximum file indicator?' 1024 01Mar2023 search 'Linux bash and how do I assign the lines of a file to an array?' readarray 17Feb2023 pinn_strOld_strNew_replace - test on webwork files, use IFS='' before read!! 16Feb2023 fileops.sh Library: key issue is practical use of library 16Feb2023 fileops.sh Library: test str_inWebPages_pout() in "$d_bin"'fileops.sh' 16Feb2023 search 'bash script to change strings in multiple files' #24************************24 # Setup, ToDos, 01Mar2023 [test, fix] code to replace Menus - pinnL_pStrPL_replace() create code to : insert pth in : '' cp Howell's *.html to "$d_webWork"'webPagesLocal/', replacing URL with pth in 1st line test use of "$d_webWork"'webPagesLocal/' 08Mar2023 def regexstr_tests iterative problem : incOne_create_seq( 0 1 c=0; c< ) should be ( 0 1 c ), 2 other ';for's work well... 14Sep2023 pOvrL_pStrPL_replace - should either [en, de]code [neither, both] [pOvr, pStrP] 28Sep2023 can I get ?I forget - in notes of something? 16Mar2024 povrL_pRgxP_replace(): in future, add options to pth file #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] ??Mar2024 #08********08 #] 16Mar2024 povrL_pRgxP_replace(): in future, add options to pth file #08********08 #] 15Mar2024 povrL_pRgxP_replace(): revamp arrays nested- test ndfs revamping : /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- data templates.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testGroupsCluster.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testOptrs.ndf 14:38$ bash "$d_bin"'fileops run.sh' ~ >> no changes!!??? oops, I used povrL_pStrP_replace 15:05$ bash "$d_bin"'fileops run.sh' ~ >> still no changes 15:23$ bash "$d_bin"'fileops run.sh' /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- data templates.ndf sed: -e expression #1, char 35: invalid reference \1 on `s' command's RHS /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testGroupsCluster.ndf sed: -e expression #1, char 35: invalid reference \1 on `s' command's RHS /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testOptrs.ndf sed: -e expression #1, char 35: invalid reference \1 on `s' command's RHS ~ Hah! was missing `\ in front of [()] - bash not geany have to replace ndfs from archive 15:23$ bash "$d_bin"'fileops run.sh' /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- data templates.ndf sed: can't read : No such file or directory /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testGroupsCluster.ndf sed: can't read : No such file or directory /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testOptrs.ndf sed: can't read : No such file or directory ~ >> files were wiped out again!?? I put archive in povrL_pRgxP_replace, then call povr_rgxP_replace no archive : if [ -s "$povr982" ]; then if [ 1 -eq "$bolArXiv982" ]; then pinn_archiveLocal "$povr982" fi while IFS='' read -r -u 983 rgxP982; do povr_rgxP_replace 0 "$povr982" "$rgxP982" done 983< "$pRgxPTmp982" change : sed "s|$rgxOld448|$rgxNew448|g" "$pov1Tmp448" >"$povrTmp448" to : sed "s|$rgxOld448|$rgxNew448|g" "$povr____448" >"$povrTmp448" 15:53$ bash "$d_bin"'fileops run.sh' /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- data templates.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testGroupsCluster.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testOptrs.ndf ~ >> now it runs without rm file contents >> but does it work? checks : tmplt grp ops y idx\([LA]*\) ndx\1 n n ary\([LA]*\) nry\1 often ary without [LA] n slc\([LA]*\) slcN\1 n ary\([A-Za-z]*\)_ nry\1_ n _slc\([LA_]*\)_ _slcN\1_ ? _replace\([A-Za-z0-9]*\)_ _put\1_ >> none of these worked!!!!? "$d_temp"'povrL_pRgxP_replace pRgxPTmp.txt' only has : _replace\([A-Za-z0-9]*\)_ _put\1_ >> oops! only one showing : _replace\([A-Za-z0-9]*\)_ _put\1_ move out of while loop! if [ -f "$pRgxPTmp982" ]; then rm "$pRgxPTmp982" fi 16:26$ bash "$d_bin"'fileops run.sh' /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- data templates.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testGroupsCluster.ndf /home/bill/web/Qnial/code develop_test/arrays nested/arrays nested- testOptrs.ndf ~ tmplt grp ops idx\([LA]*\) ndx\1 ary\([LA]*\) nry\1 often ary without [LA] slc\([LA]*\) slcN\1 ary\([A-Za-z]*\)_ nry\1_ _slc\([LA_]*\)_ _slcN\1_ _replace\([A-Za-z0-9]*\)_ _put\1_ OK examples : nry_ _ndx_ _slcN_ >> actually, it looks like it mostly worked! 16:31 take a break, I'm tired #08********08 #] 15Mar2024 check rm [povr_pStrP_replace, povr_pRgxP_replace, povrL_rgxP_replace] will no longer use! (error prone, excess [code, opNam]) I updated povrL_pRgxP_replace +-----+ olde code # povr_pStrP_replace(bolArXiv bolChrCd povr pStrP) sed replace encoded (pStrP, povr) # pStrP : put dir changes AFTER pth changes - safer, [no-tab, empty] pStrP lines are OK # example see : "$d_bin"'0_test/fileops test.sh' # tightly tied to function called, povr_strP_replace : easy to make symbol errors!! # www.BillHowell.ca 01Jun2021 intitial, 03Mar2023 unfinished, 07Aug2023 revamped # 16Sep2023 handle [no-tab, empty lines in pStrP] povr_pStrP_replace() { bolArXiv607="$1" # 1= archive povr bolChrCd607="$2" # 1= escape (code) human <--> sed search-replace povr____607="$3" # file to overwrite after sed search-replace pStrP___607="$4" # str[Old, New] search-replace pairs # echo >>"$pLog607" "povr = $povr____607" # echo >>"$pLog607" "pStrP = $pStrP___607" povr_tmp607="$d_temp"'povr_pStrP_replace povr temp.txt' pStrPtmp607="$d_temp"'povr_pStrP_replace pStrP temp.txt' if [[ -s "$povr____607" && -s "$pStrP___607" ]]; then if [ 1 -eq "$bolArXiv607" ]; then pinn_archiveLocal "$povr____607" fi if [ 1 -eq "$bolChrCd607" ]; then pHum_sed_pCde "$povr____607" "$povr_tmp607" pHum_sed_pCde "$pStrP___607" "$pStrPtmp607" else cp -p "$povr____607" "$povr_tmp607" cp "$pStrP___607" "$pStrPtmp607" fi while IFS='' read -r -u 607 strP607; do povr_strP_replace_run "$povr_tmp607" "$strP607" done 607< "$pStrPtmp607" if [ 1 -eq "$bolChrCd607" ]; then pCde_sed_pHum "$povr_tmp607" "$povr____607" else mv "$povr_tmp607" "$povr____607" fi else date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss") echo >>"$pLog384" "$date_ymdhms povr_pStrP_replace error: OR[povr, pStrPL] doesnt exist :" echo >>"$pLog384" "povr = $povr____384" echo >>"$pLog384" "pStrP = $pStrP___384" echo >>"$pLog384" '' fi } # povrL_strP_replace(bolArXiv bolChrCd povrL strP) sed replace encoded (pStr, povrL) # NO LONGER available - dangerous mixups, just use povrL_pStrP_replace # povr_pRgxP_replace(bolArXiv bolChrCd povr pRgxP) sed replace encoded (pRgxP, povr) # www.BillHowell.ca 17Sep2023 initial copy of strP form, some adjustments povr_pRgxP_replace() { bolArXiv457="$1" # 1= archive povr povr____457="$2" # file to overwrite after sed search-replace pRgxP___457="$3" # str[Old, New] search-replace pairs # echo >>"$pLog982" "povr = $povr____457" # echo >>"$pLog982" "pRgxP = $pRgxP___457" #pLog982 = 'povrL_pRgxP_replace funcFamily log.txt', defined in Setup section above if [[ -s "$povr____457" && -s "$pRgxP___457" ]]; then if [ 1 -eq "$bolArXiv457" ]; then pinn_archiveLocal "$povr____457" fi while IFS='' read -r -u 457 rgxP457; do povr_rgxP_replace 0 "$povr____457" "$rgxP457" done 457< "$pRgxP___457" else date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss") echo >>"$pLog982" "$date_ymdhms povr_pRgxP_replace error: OR[povr, pRgxPL] doesnt exist :" echo >>"$pLog982" "povr = $povr____457" echo >>"$pLog982" "pRgxP = $pRgxP___457" echo >>"$pLog982" '' fi } # povrL_rgxP_replace(bolArXiv bolChrCd povrL rgxP) sed replace encoded (pStr, povrL) UNTESTED! # [all povrL, rgxP] are escaped if p[ov, st]Esc961 == 1 # z_Archive each povrL (file listed), rgxP=(strOld, strNew) # tightly tied to function called, povr_rgxP_replace : easy to make symbol errors!! # www.BillHowell.ca 17Sep2023 initial copy of strP form, some adjustments povrL_rgxP_replace() { bolArXiv961="$1" povrL___961="$2" rgxP____961="$3" #pLog982 = 'povrL_pRgxP_replace funcFamily log.txt', defined in Setup section above if [ -s "$povrL961" ]; then while IFS='' read -u 961 povr961; do povr_rgxP_replace "$bolArXiv961" "$povr961" "$rgxP____961" done 961<"$povrL___961" else date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss") echo >>"$pLog982" "$date_ymdhms povrL_rgxP_replace error: povrL doesnt exist : " echo >>"$pLog982" "povrL : $povrL___961" echo >>"$pLog982" '' fi } #08********08 #] 27Feb2024 change povrL_pStrP_replace because of bookmarks: '^#] ' comment, not `# change: chrOne=0 chrOne=$( echo "$strP384" | cut --bytes=1 ) if ! [ '#] ' == "$chrOne" ]; then to: commentChrs=0 commentChrs=$( echo "$strP384" | cut --bytes=1,2,3 ) if ! [ '#] ' == "$commentChrs" ]; then test : 14:25$ strP384='#] 27Feb2024 OOPS!!! ^# makes function ignore line - changes wont be made' ~ 14:25$ echo "$strP384" | cut --bytes=1,2,3 ~ 14:25$ strP384='# 27Feb2024 OOPS!!! ^# makes function ignore line - changes wont be made' ~ 14:26$ echo "$strP384" | cut --bytes=1,2,3 # 2 ~ >> OK, works #08********08 #] 26Feb2024 fileops.sh add pth_get_ext() - get extension without fname from pth +-----+ olde code in [fileops.sh - none, fileops run.sh - none, 0_tests/fileops test.sh - none], search pth_get_fNoExt replace pth_get_fnmNoExt # pth_get_fNoExt(pth) - get fNam without extension (NOT pth!) # 23Sep2023 initial pth_get_fNoExt() { path551="$1" fNam551=$( pth_get_fnam "$path551" ) bolPth551=$( echo "$fNam551" | grep "\/" ) if [[ -z "$bolPth551" ]]; then fNoExt551=$( echo "$fNam551" | sed 's|\(.*\)\..*|\1|' ) else fNoExt551="fNam_get_fNoExt error, isPth : $fNam551" fi echo "$fNoExt551" } #08********08 #] 24Feb2024 'pStrPAll_L change.txt' - are [^#, whitespace] lines ignred?? while IFS='' read -r -u 385 strP384; do # screen out [comment, empty] lines # tests if strP has ONE tab - 11Oct2023 needs fix : grep -c -o 'ztbz' or whatever #bolTabInStr=$( echo "$strP384" | sed 's|\x9|ztbz|' | grep -c -o 'ztbz' ) nTab=$( echo "$strP384" | tr \\t \\n | wc -l ) nTab=$(( $nTab - 1 )) if [[ 1 = "$nTab" ]]; then # both of the following are in Cde format (tab=\x9 is NOT translated!) strFnd384=$( echo "$strP384" | sed 's|\x9.*||' ) nStrFnd384=$( grep -c "$strFnd384" "$povr_tmp384" ) if [[ 0 < "$nStrFnd384" ]]; then echo >>"$pLog384" "$nStrFnd384 : $strP384" povr_strP_replace_run "$povr_tmp384" "$strP384" fi fi done 385< "$pStrPtmp384" >> whitespace is taken care of >> ^# is NOT, so add that changed to : while IFS='' read -r -u 385 strP384; do # screen out [comment, empty] lines # tests if strP has ONE tab - 11Oct2023 needs fix : grep -c -o 'ztbz' or whatever # also ignores lines without a tab #bolTabInStr=$( echo "$strP384" | sed 's|\x9|ztbz|' | grep -c -o 'ztbz' ) nTab=$( echo "$strP384" | tr \\t \\n | wc -l ) nTab=$(( $nTab - 1 )) chrOne=$( echo "$strP384" | cut --bytes=1 ) if [ '#' == "$chrOne" ]; then if [[ 1 = "$nTab" ]]; then # both of the following are in Cde format (tab=\x9 is NOT translated!) strFnd384=$( echo "$strP384" | sed 's|\x9.*||' ) nStrFnd384=$( grep -c "$strFnd384" "$povr_tmp384" ) if [[ 0 < "$nStrFnd384" ]]; then echo >>"$pLog384" "$nStrFnd384 : $strP384" povr_strP_replace_run "$povr_tmp384" "$strP384" fi fi fi done 385< "$pStrPtmp384" +-----+ olde code dangerous - just remove from fileops.sh!! : # povrL_strP_replace(bolArXiv bolChrCd povrL strP) sed replace encoded (pStr, povrL) UNTESTED! # [all povrL, strP] are escaped if p[ov, st]Esc961 == 1 # z_Archive each povrL (file listed), strP=(strOld, strNew) # tightly tied to function called, povr_strP_replace : easy to make symbol errors!! # www.BillHowell.ca 02Jun2021 intitial, 05Aug2023 upgrade with chrEncoding # 14Sep2023 inefficient but simple: povrL_pStr[P]_replace keep encoding pStrP with each pOvr # 16Sep2023 handle [no-tab, empty lines in pStrP] # 10Oct2023 pLog384="$d_bin"'bin logs/povrL_pStrP_replace funcFamily pLog.txt' povrL_strP_replace() { date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss") echo >>"$p_log" "$date_ymdhms povrL_strP_replace" bolArXiv961="$1" bolChrCd961="$2" povrL___961="$3" strP____961="$4" # pLog384 ='povrL_pStrP_replace funcFamily pLog.txt', defined in Setup section above # 11Oct2023 missing [check, code]s of [povr, strP, etc] if [ -s "$povrL961" ]; then while IFS='' read -u 961 povr961; do povr_strP_replace_run "$povr961" "$strP____961" done 961<"$povrL___961" else date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss") echo >>"$pLog384" "$date_ymdhms povrL_strP_replace error: povrL doesnt exist : " echo >>"$pLog384" "povrL : $povrL___961" echo >>"$pLog384" '' fi } #08********08 #] 16Feb2024 post changes, run dWeb_get_pHtmWebYesNonL 15:20$ bash "$d_bin"'webSite update local.sh' find all html files /home/bill/web/bin/fileops.sh: line 2914: : No such file or directory extract webPages from htmlL: they have strTst /home/bill/web/bin/fileops.sh: line 1325: : No such file or directory diff: pth_get_dArchive error, OR[no-exist, isP] pth_get_dir error, OR[no-exist, isDir] : /home/bill/web/webWork/pWebYesL.txtfNam_get_fNoExt error, isPth : pth_get_fnam error, OR[no-exist, isDir] /home/bill/web/webWork/pWebYesL.txt archive.fNam_get_ext error, isPth : pth_get_fnam error, OR[no-exist, isDir] /home/bill/web/webWork/pWebYesL.txt: No such file or directory diff: /home/bill/web/webWork/pWebYesL.txt: No such file or directory diff: pth_get_dArchive error, OR[no-exist, isP] pth_get_dir error, OR[no-exist, isDir] : /home/bill/web/webWork/pWebNo_L.txtfNam_get_fNoExt error, isPth : pth_get_fnam error, OR[no-exist, isDir] /home/bill/web/webWork/pWebNo_L.txt archive.fNam_get_ext error, isPth : pth_get_fnam error, OR[no-exist, isDir] /home/bill/web/webWork/pWebNo_L.txt: No such file or directory diff: /home/bill/web/webWork/pWebNo_L.txt: No such file or directory grep: /home/bill/web/webWork/pWebNo_L.txt: No such file or directory ~ pinnL_lineIdx_strTst_split_pYes_pNo() : test # 16Feb2024 test, see 'fileops notes.txt' # 20:39$ line333=$( sed -n '1{p;q}' "$pinn333" ) # pinn333="$d_web"'home.html' # strTst_333=' ~ 20:40$ line333=$( echo "$line333" | cut -c 1-"$strTst_len333" ) ~ 20:40$ echo "$line333" ~ +-----+ >> 1st command OK, 2nd fails! +-----+ 20:44$ echo "$strTst_769"