Friday, November 19, 2010

How to transpose output/file in bash

for i in {1..100}; do echo $i; done | psc -r | sc -W% -

Random words generator in bash (random line reader)

n=$(cat /usr/share/dict/words | wc -l)
sed $(( ($RANDOM * 32768 + $RANDOM) % n ))"q;d" /usr/share/dict/words

How to replace some text in next line that forwards after matched to current line

#!/bin/sh
sed '/ONE/ {
N
s/TWO//
}' < text.txt > text.txt.tmp

Wednesday, November 10, 2010

SQL for delete duplicates

delete from table where id in (select (select id from table where col82 = x.col82 order by id asc limit 1) from (select count(id) cnt, col82 from table group by col82 order by cnt desc) x where x.cnt > 1);

Friday, November 5, 2010

Mini one page web server by using netcat (nc)

It will be helpful for debugging requests. You need bash and nc.
For some reasons debian and ubuntu have different net cat's version with different syntax:
- debian:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -v -v -q 1 -lp 60000; do echo ""; done

- ubuntu:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -lv 60000; do echo ""; done

To test it use command: netcat localhost 60000