In *nix, how do I display (cat) a file with no line-wrapping: longer lines should be cut such that they fit into screen's width.
According to "less" viewer help, it is disabled with -S or --chop-long-lines flags.
There is no difference from a user point of view. These commands do the same thing. Technically the difference is in what program opens the file: the cat program or the shell that runs it.
Modes such as Long Lines wrap lines on word boundaries as you type, by inserting temporary line-ending characters. These are removed when you save the buffer to a file or copy its text for yanking elsewhere, so they are only for display purposes.
You may be looking for fmt
:
fmt file
This pretty aggressively reformats your text, so it may do more than what you want.
Alternatively, the cut
command can cut text to a specific column width, discarding text beyond the right margin:
cat file | cut -c1-80
Another handy option is the less -S
command, which displays a file in a full screen window with left/right scrolling for long lines:
less -S file
Note that cut
accepts a filename as an argument.
This seems to work for me:
watch 'bash -c "cut -c -$COLUMNS file"'
For testing, I added a right margin:
watch 'bash -c "cut -c -$(($COLUMNS-10)) file"'
When I resized my terminal, the truncation was updated to match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With