Mercurial > repo
comparison bin/med @ 8131:02c762f3dc02
<moon_> ` mv DMCj bin/med
author | HackBot |
---|---|
date | Wed, 25 May 2016 01:13:45 +0000 |
parents | DMCj@4b446e13635d |
children | e8a19ae4bae5 |
comparison
equal
deleted
inserted
replaced
8130:4b446e13635d | 8131:02c762f3dc02 |
---|---|
1 #! /bin/bash | |
2 numcheck='^[0-9]\+$' | |
3 add_after_line () { { sed "$1q"; echo "$2"; sed "1,$1d"; } < "$3" > /tmp/medtmp; mv /tmp/medtmp "$3"; } #Thanks izabera! | |
4 if [ "$1" == "rl" ]; then | |
5 if [[ "$2" =~ $numcheck ]]; then | |
6 echo "error: Not a number" >&2;exit 1 | |
7 fi | |
8 NUM="$2" | |
9 cat "$3" | sed "${NUM}q;d" #Read line command | |
10 exit 0 | |
11 fi | |
12 if [ "$1" == "ap" ]; then | |
13 filename="$3" | |
14 echo "$2" >> "$filename" #Append command | |
15 exit 0 | |
16 fi | |
17 if [ "$1" == "hp" ]; then | |
18 echo "View the inside of the file for more info, rl, anyone?" | |
19 exit 0 | |
20 fi | |
21 if [ "$1" == "il" ]; then #insert at | |
22 if [[ "$2" =~ $numcheck ]]; then | |
23 echo "error: Not a number" >&2;exit 1 | |
24 fi | |
25 | |
26 add_after_line "$2" "$3" "$4" | |
27 exit 0 | |
28 fi | |
29 |