Skip to content

Instantly share code, notes, and snippets.

@leetschau
Last active February 5, 2020 07:23
Show Gist options
  • Save leetschau/166502e10a390cdfcda9de87242ad2ca to your computer and use it in GitHub Desktop.
Save leetschau/166502e10a390cdfcda9de87242ad2ca to your computer and use it in GitHub Desktop.
fetch lines in a file with even intervals and window size
#!/bin/sh
# Function:
# print $output_num sections by order,
# each have $sec_num adjacent records
# from file $inp
inp=$1
output_num=$2
sec_num=$3
total_lines=$(<$inp wc -l)
intval=$(($total_lines / $output_num))
for idx in $(seq 1 $intval $total_lines); do
nr_list=${nr_list}" NR >= $idx && NR < $idx + $sec_num;";
done
awk "$nr_list" $inp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment