0

I am looking for a single line command to print a line in a certain percentile of a large text file. My preferred solution is something based on sed, wc -l, and/or head/tail as I already know how to do that with awk and wc -l. To make it more clear, if my file has 1K lines of text, I need to print for example the (95%*1K)th line of that file.

user2517676
  • 969
  • 6
  • 15
  • 25

2 Answers2

1
head -`wc -l file | awk '{print(int(0.95*$1))}'` file | tail -n 1
user31264
  • 6,557
  • 3
  • 26
  • 40
1

In bash:

head -`echo scale=0\;$(cat file|wc -l)\*95/100 | bc -l` file | tail -n 1
user31264
  • 6,557
  • 3
  • 26
  • 40