#!/bin/sh # csv_destroyer # RTH 11/01/07 # # Sample program to show off the most common and useful function of SED # Like AWK, SED reads in one line of the file at a time and allows you to fiddle # * Unlike AWK, SED automatically prints to stdout for you to redirect * # # Note similarity of syntax to AWK: # sed 'regular expressions and substitutions' INPUT > OUTPUT # s/,/\t/g == Substitute/THIS/FOR THIS/Everywhere in the current line # Think C style for newline, tab, etc. echo "" echo "SED output, changing commas to tabs" sed 's/,/\t/g' V1280Sco_csvhead.dat # This is an example especially you can do snazzy things # in awk, like change what it sees at the field separator. # Also further proof that if you know C, you'll be fine. AWK has printf as well # side note - reason this initially failed during my talk is that my laptop's # version of AWK does NOT accept %lf as a format statement as was originally # written, but the version on comet does. Ditto that ** failed on my laptop, # while ^ raises exponents as expected. Be careful! echo "" echo "AWK output, defining commas as field separators" awk 'BEGIN {FS=","} {printf "%f\t%f\t%e\n",$1,$2,$3}' V1280Sco_csvhead.dat echo ""