bash - Putting awk in a function -
i have 4 awks similiar want put them in function. awk code is...
awk -v mypath="$mypath" -v file_ext="$file_ext" -v name_of_file="$name_of_file" -v date="$date" -v pattern="$stored_procs_begin" ' $0 ~ pattern { rec = $1 ofs $2 ofs $4 ofs $7 (i=9; i<=nf; i++) { rec = rec ofs $i if ($i ~ /\([01]\)/) { break } } print rec >> "'$mypath''$name_of_file''$date'.'$file_ext'" } ' "$file_location" so pattern , regular expression differ. how can put awk in function can replace pattern $1 , /([01])/ $2 if use in awk?
edit: thinking can do...
printfmt(){ awk -v ....... $0 ~ patten { rec.. for.. rec.. if($i ~ search) break print rec then call printfmt set?
}
not sure problem since have in code need maybe simplifying bit:
$ cat tst.sh function prtstuff() { awk -v x="$1" 'begin{ print x }' } prtstuff "foo" prtstuff "---" prtstuff "bar" $ ./tst.sh foo --- bar
Comments
Post a Comment