regex - I changed repetitive awk expressions into one function -
i had 8 awk expressions differed 2 patterns searching for. created awk function improve code, wont work. doing is...
printfmt () { awk -v mypath="$mypath" -v file_ext="$file_ext" -v name_of_file="$name_of_file" -v date="$date" -v pattern="$1" -v search="$2" ' $0 ~ pattern { rec = $1 ofs $2 ofs $4 ofs $7 (i=9; i<=nf; i++) { rec = rec ofs $i if ($i ~ search) { break } } print rec >> "'$mypath''$name_of_file''$date'.'$file_ext'" } ' "$file_location" }
and calling printfmt "$stored_procs_finished" "/([01])/"
. code above except instead of search /([01])/. there syntax missing?
do , read book effective awk programming, 4th edition, arnold robbins:
printfmt () { awk -v regexp1="$1" -v regexp2="$2" ' $0 ~ regexp1 { rec = $1 ofs $2 ofs $4 ofs $7 (i=9; i<=nf; i++) { rec = rec ofs $i if ($i ~ regexp2) { break } } print rec } ' "$file_location" >> "${mypath}${name_of_file}${date}.${file_ext}" } printfmt "$stored_procs_finished" "[01]"
your use of all-caps variable names bad - that's exported shell variables only.
don't use word "pattern" it's ambiguous, , "search" meaningless - come 2 meaningful names variables named regexp1 , regexp2.
Comments
Post a Comment