Database Reference
In-Depth Information
print_body
exit
1
;;
h
)
usage
exit
1
;;
esac
done
get_header
print_header
$OLDHEADER
If no arguments are provided, the header of the CSV file is printed:
$
< tips.csv header
bill,tip,sex,smoker,day,time,size
This is the same as
head -n 1
. If the header spans more than one row, which is gen‐
erally not recommended, you can specify
-n 2
. We can also add a header to a
CSV file:
$
seq 5 | header -a count
count
1
2
3
4
5
This is equivalent to
echo "count" | cat - <(seq 5)
. Deleting a header is done
with the
-d
option:
$
< iris.csv header -d | head
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5.0,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
This is similar to
tail -n +2
, but it's a bit easier to remember. Replacing a header,
which is basically first deleting a header and then adding one if you look at the pre‐
ceding source code, is accomplished with specifying
-r
. Here, we combine it with
body
:
$
seq 5 | header -a line | body wc -l | header -r count
count
5