#] #] ********************* #] "$d_bin"'email scripts/email - process folders notes.txt'' www.BillHowell.ca 12Jan2018 initial ****************** 12Jan2018 d_folder="/media/bill/SWAPPER/180112 INNS President vote email.sbd/" ls -1 "$d_folder" | grep --invert-match ".msf" | tr \\n \\0 | xargs -0 --max-args=1 echo "\"$d_folder" cat - | grep -o "\([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" | xargs sed "'s/^/\$d_folder/'" find "$d_folder" | grep --invert-match ".msf" | tr \\n \\0 | xargs -0 --max-args=1 cat find "$d_folder" | grep --invert-match ".msf" | sed 's/^/"/' | sed 's/$/"/' find "$d_folder" | grep --invert-match ".msf" | xargs --max-args=1 -I p_folder bash -c '{ echo p_folder; echo p_folder" emails.txt"; }' cat "$d_folder""Bad address" | grep -o "\([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" >> works great ******************** 14Jan2018 search "Linux xargs and using an environmental variable with multiple commands" https://unix.stackexchange.com/questions/381436/xargs-with-multiple-argument-substitutions-use-environment-variable-argument-a/381443 Just remove them from single quotes: ... sh -c 'echo "Dumping file: "{} >> '"$2"'; w3m {} >> '"$2"' 2>&1' The shell will glue everything together. answered Jul 24 '17 at 14:31, jimmij ls -1 "$d_folder" | grep --invert-match ".msf" | xargs --max-args=1 -I p_folder bash -c ' echo '"$d_folder"'"p_folder"; echo '"$d_folder"'"p_folder emails.txt"; ' sh "$d_folder" ls -1 "$d_folder" | grep --invert-match ".msf" | xargs --max-args=1 -I p_folder bash -c ' echo "'"$d_folder"'p_folder"; echo "'"$d_folder"'p_folder emails.txt" ' ls -1 "$d_folder" | grep --invert-match ".msf" | xargs --max-args=1 -I p_folder bash -c ' echo >"'"$d_folder"'p_folder emails.txt" '"$d_folder"'"p_folder"' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I p_folder bash -c 'echo >"'$d_folder'p_folder emails.txt" "'$d_folder'p_folder"' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I p_folder bash -c 'echo "'$d_folder'p_folder emails.txt" "'$d_folder'p_folder"' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I p_folder bash -c 'echo \"'"$d_folder"'p_folder emails.txt\" \"'"$d_folder"'p_folder\"' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I email_folder bash -c 'echo o "\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\"' >> good output >> how is this corrupted in xargs expression??? ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I email_folder bash -c 'grep -o \""\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\"' >> Same old errors : grep: INNS: No such file or directory grep: President: No such file or directory grep: vote: No such file or directory grep: email.sbd/Bad: No such file or directory grep: address": No such file or directory grep: INNS: No such file or directory grep: President: No such file or directory grep: vote: No such file or directory grep: email.sbd/confirm: No such file or directory grep: to: No such file or directory grep: pass": No such file or directory .. etc ********************* 15Jan2018 - take the simple rout - create a bash script file, then run it d_folder="/media/bill/SWAPPER/180112 INNS President vote email.sbd/" p_script="$d_folder""00_grep email folders.sh" rm "$p_script" test_emailLine="From: \"Huang, Catherine\" To: \"Bill Howell. Hussar. Alberta. Canada\" " echo "$test_emailLine" | grep -o "\([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" >> OK ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | xargs --max-args=1 -I email_folder bash -c 'echo \"grep \-o "\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\" \>\>\"'"$p_script"'\" \"' >> OK, good output. example : "grep -o "\([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" "/media/bill/SWAPPER/180112 INNS President vote email.sbd/Bad address" >>"/media/bill/SWAPPER/180112 INNS President vote email.sbd/00_grep email folders.sh" " " ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder bash -c 'grep \-o "\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\" \>\>\"'"$p_script"'\" 'email_folder ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder echo 'grep \-o "\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\" \>\>\"'"$p_script"'\" ' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder echo 'grep \-o "\"\\([-A-Za-z0-9._]\\+\\)\\(@\\)\\([-A-Za-z0-9._]\\+\\)\" "\"\'"$d_folder"'email_folder\" \>\>\"'"$p_script"'\" ' ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder echo 'grep -o "([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" "'"$d_folder"'email_folder" >>"'"$p_script"'" ' >> Great (OOPS! - >>"'"$p_script"'" is wrong, should be folder!) ls -1 "$d_folder" | grep --invert-match ".msf" | grep --invert-match ".txt" | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder echo >>"$p_script" 'grep -o "\([-A-Za-z0-9._]\+\)\(@\)\([-A-Za-z0-9._]\+\)" "'"$d_folder"'email_folder" >>"'"$d_folder"'email_folder.txt" ' >> OK email_folder bash "$p_script" >> OK ls -1 "$d_folder" | grep ".txt" | sed 's/.txt//' | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder echo 'sort -c --unique >>"'"$d_folder"'email_folder email_sort&cull.txt" "'"$d_folder"'email_folder" ' >> NOT OK... ls -1 "$d_folder" | grep ".txt" | sed 's/.txt//' | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder bash -c 'sort --unique >>"'"$d_folder"'email_folder email_sort&cull.txt" "'"$d_folder"'email_folder.txt" ' >> OK, but reprocesses ".txt" files, so name outputs as ".txt2" ls -1 "$d_folder" | grep ".txt$" | sed 's/.txt//' | tr \\n \\0 | xargs -0 --max-args=1 -I email_folder bash -c 'sort --unique >>"'"$d_folder"'email_folder email_sort&cull.txt2" "'"$d_folder"'email_folder.txt" ' >> OK, seems to work great ******************************************** Now to remove [key protected), server, garbage] emails +-----+ Garbage emails - build a script I need to process a text file with a list of "bad" indicators, plus another with "key emails" to protect define a function to cull members of a sorted list from another sorted list see brelow for example from http://www.tldp.org/LDP/abs/html/textproc.html +-----+ http://www.tldp.org/LDP/abs/html/textproc.html look The command look works like grep, but does a lookup on a "dictionary," a sorted word list. By default, look searches for a match in /usr/dict/words, but a different dictionary file may be specified. Example 16-20. Checking words in a list for validity #!/bin/bash # lookup: Does a dictionary lookup on each word in a data file. file=words.data # Data file from which to read words to test. echo echo "Testing file $file" echo while [ "$word" != end ] # Last word in data file. do # ^^^ read word # From data file, because of redirection at end of loop. look $word > /dev/null # Don't want to display lines in dictionary file. # Searches for words in the file /usr/share/dict/words #+ (usually a link to linux.words). lookup=$? # Exit status of 'look' command. if [ "$lookup" -eq 0 ] then echo "\"$word\" is valid." else echo "\"$word\" is invalid." fi done <"$file" # Redirects stdin to $file, so "reads" come from there. echo exit 0 # ---------------------------------------------------------------- # Code below line will not execute because of "exit" command above. # Stephane Chazelas proposes the following, more concise alternative: while read word && [[ $word != end ]] do if look "$word" > /dev/null then echo "\"$word\" is valid." else echo "\"$word\" is invalid." fi done <"$file" exit 0 +-----+ # cull_sList_from_sList() { while read word && [[ $word != end ]] do if look -f "$word" > /dev/null "$1" then echo "\"$word\" is valid." else echo "\"$word\" is invalid." fi done <"$file" exit 0 } Eventiually this became, for an example : # see http://www.tldp.org/LDP/abs/html/textproc.html cull_sList_from_sList() { rm "$3" while read line && [[ $line != end ]] do while read badder && [[ $badder != end ]] do flag_bad=0 grepper="$( echo "$line" | grep -F "$badder" )" if [ "$grepper" = "$line" ] then flag_bad=1 break fi done <"$1" if [ "$flag_bad" = 0 ] then echo >>"$3" "$line" fi done <"$2" } cull_sList_from_sList "/media/bill/SWAPPER/bin/email - bad tokens & key emails.txt" "/media/bill/SWAPPER/180112 INNS President vote email.sbd/Bad address email_sort&cull.txt2" "/media/bill/SWAPPER/180112 INNS President vote email.sbd/Bad address email_sort&cull.txt3" ls -1 "$d_folder" | grep ".txt2$" | sed 's/.txt2$//' | tr \\n \\0 | xargs -0 --max-args=1 -I email_sortCull bash -c 'p_cull_sList_from_sList "'"$d_folder"'email_sortCull.txt2" ' /media/bill/SWAPPER/binemail - bad tokens & key emails.txt ... -bounce- MAILER-DAEMON .lexi.net billhowell association-resources # enddoc