« Simple median in python | Main | Calgary's winter landscape »

Awk csv and cut the header...

Something I keep having to look up how todo so I'm putting it here for future reference:

Suppose you have a comma separated file, say the list of Abell clusters: e.g. first line:

1,1.89167,16.50972,0.1249,514.3,3.342

and you want to convert this into a nice tab spaced data set and cut off the header...

awk -F',' '{printf("%10.8f\t%10.8f\t%10.8f\t%10.8f\t%10.8f\t%10.8f\n", $1,$2,$3,$4,$5,$16)}' abell_all.csv > temp_abellcut

len=$(wc -l temp_abellcut | awk '{print $1 -1}')
tail -n $len temp_abellcut > abell_all.dat
rm -rf temp_abellcut
echo "id ra dec z D search_radius" > abell_all.header


... and bob's ya uncle.

TrackBack

TrackBack URL for this entry:
http://krioma.net/cgi-bin/MT-3.38/mt-tb.cgi/471

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on November 24, 2010 4:25 AM.

The previous post in this blog was Simple median in python.

The next post in this blog is Calgary's winter landscape.

Many more can be found on the main index page or by looking through the archives.

Get Firefox! Valid XHTML 1.0! Valid CSS! RSS Feed BlogUniverse - listed Powered by Apache Creative Commons License ringsofsaturnrock's Most Interesting Photos on Flickriver

Powered by
Movable Type 3.38