Cleaning up files with awk

Published at

#terminal-shell

This TIL is more than a year old. Some details may have changed.

Needed to clean up a JSON file, after I copied the JSON from the browser and got the line numbers too.

Move every even line to clean file

SHELL
$ awk 'NR % 2 == 0' dirty.json > clean.json

Move every odd line to clean file

SHELL
$ awk 'NR % 2 != 0' dirty.json > clean.json