sed-find-pattern-and-append.sh 472 B

1234567891011
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. [[ -f "$2" ]] && 2=$(cat "$2")
  4. # sed -i.bak '/l6:6:wait:\/etc\/rc.d\/rc 6/ a \/sbin\/if-pp-to-cng' /etc/inittab
  5. sed -i.bak "/${1}/ a ${2}" "${@:3}"
  6. # sed "${line_index} c${new_value}" "$i"
  7. # awk -v new="/sbin/if-pp-to-cng" '($0=="l6:6:wait:/etc/rc.d/rc 6") {$0=$0"\n"new} 1' /etc/inittab
  8. # # Why use a variable, add it directly
  9. # awk '($0=="l6:6:wait:/etc/rc.d/rc 6") {$0=$0"\n/sbin/if-pp-to-cng"} 1' /etc/inittab