Stochastic Nonsense

Put something smart here.

Vi Swapping Order of Tables of Counts and Labels

A note to myself: if you have a table of counts and labels, perhaps created by something | something | uniq -c, you can swap the order of the labels and the counts / change the order of columns in vi via the following regex.

1
2
3
4
1 labelone
2 labeltwo
3 labelthree
99 label99

highlight in visual mode with V then run the following regex: s/\(\d\+\)\s\+\([a-zA-Z0-9_]*\)/\2 \1/

1
2
3
4
labelone 1
labeltwo 2
labelthree 3
label99 99

or turn them into the correct format for a python dict via s/\(\d\+\)\s\+\([a-zA-Z0-9_]*\)/'\2': \1,/

1
2
3
4
'labelone': 1,
'labeltwo': 2,
'labelthree': 3,
'label99': 99,