shithub: rc

Download patch

ref: c35c684b087c526622e60d5fa6ab098c30238f16
parent: 3d98f22b01f61b93c3bcc6ffe3f0eb0fa2d01f98
author: qwx <qwx@sciops.net>
date: Thu Jan 9 09:34:54 EST 2020

add rc: general helper scripts

diff: cannot open b/rc//null: file does not exist: 'b/rc//null'
--- /dev/null
+++ b/rc/shl
@@ -1,0 +1,11 @@
+#!/bin/rc
+awk '
+BEGIN{
+	srand()
+}
+{
+	printf "%06d	%s\n", rand() * 1000000, $0
+}
+' |\
+	sort -n |\
+	sed 's/^[0-9]+	//'
--- /dev/null
+++ b/rc/tac
@@ -1,0 +1,8 @@
+#!/bin/awk -f
+{
+	l[NR] = $0
+}
+END{
+	while(NR > 0)
+		print l[NR--]
+}
--- /dev/null
+++ b/rc/unhex
@@ -1,0 +1,17 @@
+#!/bin/awk -f
+# dd ... | xd -1x | ssam '...' | unhex | dd ...
+function hex(s, v){
+	if(s ~ /^0x/)
+		s = substr(s, 3)
+	for(n=1; n<=length(s); n++)
+		v = v * 16 + h[substr(s, n, 1)]
+	return v
+}
+BEGIN{
+	for(n=0; n<16; n++)
+		h[sprintf("%x", n)] = n
+}
+{
+	for(i=2; i<=NF; i++)
+		printf "%c", hex("0x" $i)
+}