sed cut replacement everything in a csv except second field

Leave a comment


sed -ne 's/[^,]*,//2p'

sed as grep and cut replacement

Leave a comment


sed -ne '/key=/{s/^.*=//,s%/%\\/%g;p}'

awk multiline csv flattener

Leave a comment


awk 'BEGIN{RS="";FS=",[\n]*";OFS="";ORS=""}{for(i=1;i<NF;i++) print $i ",";print $NF "\n"}'

awk verbose multiline record flattener

Leave a comment


awk 'NF > 0{printf $0};NF == 0{printf "\n"}'

awk combine multiline records separated by a blank line

Leave a comment


awk '{printf FS?$0:"\n"}'

Python 2 print headers and content of url

Leave a comment


python -c 'import urllib2; resp = urllib2.urlopen("http://localhost:10888/cgi-bin/hello.py"); print resp.info(), resp.read()'

Python 3 print headers and content of url

Leave a comment


python3 -c 'import urllib.request; resp = urllib.request.urlopen("http://localhost:10888/cgi-bin/hello.py"); print(resp.info(), resp.read().decode("utf-8"))'

Python 3 CGI web server with cgi-bin directory

3 Comments


python3 -c 'import http.server; http.server.HTTPServer(("", 10888), http.server.CGIHTTPRequestHandler).serve_forever()'

Python cgi web server with cgi-bin and htbin

Leave a comment


python -m CGIHTTPServer 10080

Python 3 web server the current directory

Leave a comment


python3 -m http.server 10030

Python web server the current directory

Leave a comment


python -m SimpleHTTPServer 10080

Python as a shell

Leave a comment


ipython -p pysh

Reversing a string in python – version special case

Leave a comment


python -c 'print "The rain in spain."[::-1]'

Reversing a string in python – version after sleeping on it

Leave a comment


python -c 'print "The rain in spain."[-1::-1]'

Reversing a string in python – version the first

6 Comments


python -c 's = "The rain in spain falls mainly on the plain."; print "".join(s[c] for c in xrange(len(s) - 1, -1, -1))'

bash hello open tcp ports

Leave a comment

bash -c 'for n in $(seq 1 1024);do (echo </dev/tcp/localhost/$n) &</dev/null && echo $n open;done'

python list sort

1 Comment

python -c 'x=["hello","my","friend"];x.sort();print x'

perl one liners begin with -e

Leave a comment

perl -e '$hw="hello world";$hw=~s/^(h)([^w]*)(w)(.*)$/H$2W$4\n/;print $hw'

sed one liners begin with -e

Leave a comment

sed -e '/World/s/.*/!/' <<<"Hello World"

awk one liners expect a code block

Leave a comment

awk '/Hello/ {print $1,$2"!"}' <<<"Hello World"

Older Entries

Follow

Get every new post delivered to your Inbox.