I assume you mean percent of lines, for this you need to know the number of lines first.
Here's one way to do it as a two-pass solution with awk:
awk 'FNR == NR { tot=NR; next } { printf( "%s %.4f\n", $0, FNR/tot) }' file file
Output:
foo 2.3 0.3333
bar 2.6 0.6667
baz 4.7 1.0000
The first block is only active during FNR == NR
i.e. the first pass. The second block takes care of the printing.
Other alternatives to determine length of file
Use NR-1
when starting second pass (FNR != NR
):
awk 'FNR != NR { if(!tot) tot=NR-1; printf( "%s %.4f\n", $0, FNR/tot) }' file file
Use wc
before running awk:
awk -v tot=$(wc -l < file) '{ printf( "%s %.4f\n", $0, FNR/tot) }' file