Reputation: 60892
I'd like to know how I can inset a line using awk
currently i created this script:
awk -F'\t' 'BEGIN {OFS="\t";} { print $1,$3,$11,"10"; }' boinc.txt | sed 1d
and the output is:
it works great!
however, i would like to prepend a line to the beginning of the output specifying the header names like "key, price, barcode, days"
desired output would be something like this:
+------------------------------------+
| key price barcode days |
+------------------------------------+
| 16112 $23.94 5014682600194 10 |
| 16126 $1.99 019688104122 10 |
| 16152 $7.99 099923118527 10 |
| 16178 $8.99 3366750130396 10 |
| 16233 $5.99 7318590001615 10 |
| 16236 $6.99 410965078691 10 |
| 16257 $8.99 7318590000397 10 |
| 16279 $5.99 7318590000113 10 |
| 16282 $5.99 7318590001387 10 |
| 16318 $6.99 723721898120 10 |
+------------------------------------+
Upvotes: 1
Views: 483
Reputation: 77185
Try this:
awk '
BEGIN { FS = OFS = "\t"; print "key", "price", "barcode", "days" }
NR > 1 { print $1, $3, $11, "10" }' boinc.txt
Note: You don't need sed
if you just tell awk
to skip over first line using NR>1
Upvotes: 4