Last active
February 5, 2020 07:23
-
-
Save leetschau/166502e10a390cdfcda9de87242ad2ca to your computer and use it in GitHub Desktop.
fetch lines in a file with even intervals and window size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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