See the comments you received and then try this (untested) as a starting point:
$ cat tst.sh #!/usr/bin/env bash tmp_file=$(mktemp) || exit 1 trap 'rm -f "$tmp_file"; exit' EXIT while getopts n:c:v:i opt; do case $opt in n) number="$OPTARG";; c) column="$OPTARG";; v) value="$OPTARG";; i) inplace=1;; *) printf>&2 '%s\n' "Usage: $0 [-f file] [-n number] [-c column] [-v value]";; esac done shift $((OPTIND-1)) if [[ -z "$column" ]]; then echo "Please specify a column number with -c." >&2 exit 1 elif [[ -z "$number" ]]; then echo "Please specify a phone number to filter by via -n" >&2 exit 1 elif [[ -z "$value" ]]; then echo "Please specify the new value via -v" >&2 exit 1 elif ! (( 1 <= column )) && (( column <= 4 )); then echo "this script can only handle cols1-4. for group editing, try ./groups.sh" >&2 exit 1 fi xform() { awk -v num="^$number" -v col="$column" -v value="$value" \ 'BEGIN{FS=OFS=","} $0 ~ num{$col=value} 1' "$@" } if [[ -n "$inplace" ]]; then if (( $# == 0 )); then echo "cannot do inplace editing as requested by -i without an input file present" >&2 exit 1 fi for file; do xform "$file" > "$tmp_file" && mv "$tmp_file" "$file" done else xform "$@" fi You should do more validation on the option arguments to ensure, for example, that the values like column that you expect to be a natural number truly are natural numbers.