I am surprised that even after 10 years, no-one has yet mentioned that cut
(from gnu coreutils) does exactly what you want. Just pipe your output to cut
:
Using a 55-column wide terminal window (just to show that this works):
$ cat cutTest.txt # shows automatic folding/wrapping
Line 1 is too long, line 1 is too long, line 1 is too l
ong, yes line 1 is too long!
Line 2 is too long, line 2 is too long, line 2 is too l
ong, yes line 2 is too long!
$ cut -c-40 < cutTest.txt # cuts after 40 columns/characters
Line 1 is too long, line 1 is too long,
Line 2 is too long, line 2 is too long,
$ cat cutTest.txt | cut -c-40 # Using a pipe
Line 1 is too long, line 1 is too long,
Line 2 is too long, line 2 is too long,
If your terminal tracks the window width (as bash
does), you can use the following to cut "at the end of the terminal's window (as per the original question):
$ cat cutTest.txt | cut -c-$COLUMNS
Line 1 is too long, line 1 is too long, line 1 is too l
Line 2 is too long, line 2 is too long, line 2 is too l