#!/bin/bash ./myprogram | tail -n N > log.txt #example #./program | tail -n 10 > log.txt (store the last 10 lines of the output in the file "log.txt")