Commit 85cd526f64
Unsigned
Layout: unified · split
README.md added +6
| @@ -0,0 +1,6 @@ | |||
| 1 | # ipatch | ||
| 2 | |||
| 3 | worlds most basic patching program written in bash *since my brain refuses to learn GNU patch* | ||
| 4 | |||
| 5 | # installing (as root) | ||
| 6 | chmod +x ipatch && mv ipatch /usr/local/bin | ||
ipatch added +10
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | [ $# -ne 3 ] && { echo "usage: ipatch <file> <line> <new line>"; exit 1; } | ||
| 3 | f=$1 n=$2 new=$3 | ||
| 4 | [ -f "$f" ] || { echo "unable to find a file named $f"; exit 1; } | ||
| 5 | [[ $n =~ ^[0-9]+$ ]] || { echo "<line> should be a number"; exit 1; } | ||
| 6 | total=$(wc -l < "$f") | ||
| 7 | (( n >= 1 && n <= total )) || { echo "<line> is out of range (1-$total)"; exit 1; } | ||
| 8 | tmp=$(mktemp) || exit 1 | ||
| 9 | NEW=$new awk -v n="$n" 'NR==n{print ENVIRON["NEW"];next}1' "$f" > "$tmp" && cat "$tmp" > "$f" | ||
| 10 | rm -f "$tmp" | ||