Mercurial > hg > cc > cirrus_shared
comparison .bash_extras @ 1:fef95c7a391f
for general use...
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Sat, 28 Feb 2026 15:51:58 +0000 |
| parents | |
| children | 6c772ae7fce2 |
comparison
equal
deleted
inserted
replaced
| 0:a6c7f23cca94 | 1:fef95c7a391f |
|---|---|
| 1 # Sourced by .bashrc and singularity runscript | |
| 2 | |
| 3 cu () | |
| 4 { | |
| 5 cvs update "$@" | egrep -v '^\?' | |
| 6 } | |
| 7 | |
| 8 lss () | |
| 9 { | |
| 10 ls -F --color=auto -lS "$@" | { | |
| 11 read one; | |
| 12 if [ -n "$one" -a "${one::5}" \!= "total" ]; then | |
| 13 echo "$one"; | |
| 14 fi; | |
| 15 cat | |
| 16 } | |
| 17 } | |
| 18 | |
| 19 ff () | |
| 20 { | |
| 21 pat=$1; | |
| 22 shift; | |
| 23 find . -iname "*$pat*" $@ | |
| 24 } | |
| 25 | |
| 26 typecat () | |
| 27 { | |
| 28 tt=$(type $1); | |
| 29 case $tt in | |
| 30 *\ is\ hashed\ *) | |
| 31 cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') | |
| 32 ;; | |
| 33 *\ is\ /*) | |
| 34 cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') | |
| 35 ;; | |
| 36 *) | |
| 37 type $1 | |
| 38 ;; | |
| 39 esac | |
| 40 } | |
| 41 | |
| 42 sus () | |
| 43 { | |
| 44 sort "$@" | uniq -c | sort -k1nr,1 | |
| 45 } | |
| 46 | |
| 47 uz () | |
| 48 { | |
| 49 igzip -dc "$@" | |
| 50 } | |
| 51 | |
| 52 function tot () | |
| 53 { | |
| 54 awk '{sum+=$1} END {printf "%u\n",sum}' | |
| 55 } | |
| 56 | |
| 57 btot () | |
| 58 { | |
| 59 python3 -c 'import sys | |
| 60 multiCol = dostats = sample = False | |
| 61 c = "" | |
| 62 p = 0 | |
| 63 q = None | |
| 64 d = 2 | |
| 65 ssq = 0 | |
| 66 while len(sys.argv)>1: | |
| 67 if multiCol and sys.argv[1][0]!="-": | |
| 68 p=1 | |
| 69 q=int(sys.argv.pop(1)) | |
| 70 elif sys.argv[1]=="-c": | |
| 71 # add commas | |
| 72 c = "," | |
| 73 sys.argv.pop(1) | |
| 74 elif sys.argv[1]=="-a": | |
| 75 # do sum etc. for all columns [p]:q | |
| 76 multiCol = True | |
| 77 sys.argv.pop(1) | |
| 78 try: | |
| 79 q = int(sys.argv.pop(1)) | |
| 80 except IndexError: | |
| 81 print("you must supply an N for multi-column") | |
| 82 exit(1) | |
| 83 elif sys.argv[1]=="-s": | |
| 84 # include mean and sample stdev | |
| 85 dostats = True | |
| 86 sample = True | |
| 87 sys.argv.pop(1) | |
| 88 elif sys.argv[1]=="-p": | |
| 89 # include mean and population stdev | |
| 90 dostats = True | |
| 91 sys.argv.pop(1) | |
| 92 elif sys.argv[1]=="-d": | |
| 93 sys.argv.pop(1) | |
| 94 d=int(sys.argv.pop(1)) | |
| 95 else: | |
| 96 break | |
| 97 n=0 | |
| 98 if multiCol: | |
| 99 w=q-p | |
| 100 import numpy as np | |
| 101 s=np.array([0]*w) | |
| 102 n=np.array([0]*w) | |
| 103 if dostats: | |
| 104 ssq=np.array([0]*w) | |
| 105 else: | |
| 106 s=0 | |
| 107 if dostats: | |
| 108 ssq=0 | |
| 109 import math | |
| 110 for l in sys.stdin: # ["1 11\n","2 22\n"]: | |
| 111 try: | |
| 112 if multiCol: | |
| 113 ll=l.split()[p:q] | |
| 114 ii=np.array([(0 if i.startswith("NaN") else int(i)) for i in ll]) | |
| 115 s+=ii | |
| 116 ssq+=ii*ii | |
| 117 n+=np.array([(0 if i.startswith("NaN") else 1) for i in ll]) | |
| 118 else: | |
| 119 if l[0]!="N": | |
| 120 i=int(l) | |
| 121 s+=i | |
| 122 if dostats: | |
| 123 ssq+=(i*i) | |
| 124 n+=1 | |
| 125 except (NameError,ValueError) as e: | |
| 126 print(l,e,file=sys.stderr) | |
| 127 if dostats: | |
| 128 if multiCol: | |
| 129 m=s/n | |
| 130 var=(ssq/n)-pow(m,2) | |
| 131 if sample: | |
| 132 var=(n/(n-1))*var | |
| 133 sd=pow(var,0.5) | |
| 134 else: | |
| 135 m=float(s)/float(n) | |
| 136 var=(float(ssq)/float(n))-pow(float(m),2) | |
| 137 if sample: | |
| 138 var=(float(n)/float(n-1))*var | |
| 139 sd=math.sqrt(var) | |
| 140 if dostats: | |
| 141 if multiCol: | |
| 142 print("\t".join(f"{i:{c}.{d}f}" for i in s)) | |
| 143 print("\t".join(f"{i:{c}.{d}f}" for i in m)) | |
| 144 print("\t".join(f"{i:{c}.{d}f}" for i in sd)) | |
| 145 else: | |
| 146 print(f"{s:}\t{m:}\t{sd:}") | |
| 147 else: | |
| 148 if multiCol: | |
| 149 print("\t".join(f"{i:}" for i in s)) | |
| 150 else: | |
| 151 print(f"{s:}") | |
| 152 | |
| 153 ' "$@" | |
| 154 } | |
| 155 | |
| 156 headtail () | |
| 157 { | |
| 158 case "$1" in -*) | |
| 159 n="$1" | |
| 160 shift | |
| 161 ;; | |
| 162 *) n="-10" | |
| 163 ;; | |
| 164 esac | |
| 165 cat "$@" | { sed -u ${n:1}q ; echo === ; tail $n ; } | |
| 166 } | |
| 167 | |
| 168 export -f cu lss ff typecat sus uz tot btot headtail |
