Skip to content

Instantly share code, notes, and snippets.

@vbajpai
Created July 18, 2012 09:31
Show Gist options
  • Save vbajpai/3135250 to your computer and use it in GitHub Desktop.
Save vbajpai/3135250 to your computer and use it in GitHub Desktop.
Strip out Values from the KV pair in a Text File
>> cat input.txt
k1:v1 k2:v2 k3:v3 ...
...
>> cat input.txt | python -c "import sys; \
lines = sys.stdin.readlines(); \
values = [[i.split(':')[1] for i in item] for item in \
[line.split() for line in lines]]; \
import os; [os.system('echo %s'%v) for v in \
['\t'.join(value) for value in values]]" > output.txt
>> cat output.txt
v1 v2 v3 ...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment