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.8ft%10.8ft%10.8ft%10.8ft%10.8ft%10.8fn”, $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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: