I wonder if there is a way to remove half the lines of a file using wc
and sed
.
I can do this:
sed -i '50,$d' myfile.txt
Which removes lines from 50 to the end of file. I can also do this:
wc -l myfile.txt
Which returns the number of lines in the file.
But what I really want to do is something like this:
wc -l myfile.txt | sed -i '{wc -l result}/2,$d' myfile.txt
- How can I tell
sed
to remove the lines starting from thewc -l
result divided by 2? - How can I do this recursively?