bash - How to remove 10 % of the lines of a (large) file? -
i have files (some > 30) want remove first 10% of lines (starting @ beginning).
with help of other stack overflow users, i've tried this:
declare -a t declare -a z j in {0..31}; t[$j]=$(wc -l < h_$j) z[$j]=$(echo "${t[$i]}"/10 | bc) sed "1,${z[$j]}d" h_$j > hh_$j done but files, , have no thought why, doesn't work. though split, couldn't find alternative allow me remove first 10 % without generating 10 different files 10 % of original file.
using tail
this uses tail remove first 10% of lines file:
tail -n+$(( $(wc -l <file) / 10 )) file using sed sed -n "$(( $(wc -l <file) / 10 ))",'$ p' file if want alter file in place, utilize sed's -i option:
sed -i -n "$(( $(wc -l <file) / 10 ))",'$ p' file for non-gnu sed (osx, etc), alternative -i may require argument specifying extension of back-up file.
bash sed split
No comments:
Post a Comment