4

I'm doing:

less -S my_database_dump.sql

In order to see the files with the lines chopped (i.e. line wrapping.) But it's not working, the lines aren't being wrapped and I need to scroll horizontally to see the entire line. What can I do?

3
  • What do you mean "scroll horizontally"? Which terminal emulator are you using? Perhaps your -S switch doesn't seem to work as expected because your terminal emulator reports too many columns, so less chops to the wrong size. May 5, 2011 at 16:33
  • I use Console for Windows. (Running bash from msysgit.) I think it reports columns correctly, because other programs wrap lines properly.
    – Ram Rachum
    May 5, 2011 at 16:42
  • None of the proposed solutions work on cygwin+conemu. No chopping happens with 'less -S' or 'less --chop-long-lines' or typing '-S' while less is running. TERM=cygwin
    – John Prior
    Dec 23, 2014 at 17:22

2 Answers 2

6

Try this:

fold -w $COLUMNS my_database_dump.sql | less

$COLUMNS is set to the terminal width by the shell. You can try other widths depending on your needs, of course. If you're running this in a script you may not have either $COLUMNS or $LINES defined - in that case you can use tput lines instead.

If you really want lines chopped (in this example, keep the first 80 chars) instead do this:

cut -c -80 my_database_dump.sql | less
4

"chop" means truncate (discard remainder of line) not fold (put remainder at start of next line).

The documented behaviour of the -S option to less is to do the opposite of what you describe.

       -S or --chop-long-lines
              Causes lines longer than the screen width to be  chopped  rather
              than  folded.   That  is, the remainder of a long line is simply
              discarded.  The default is to fold long lines; that is,  display
              the remainder on the next line.

(I think of -S as meaning "Scroll Sideways to See end of line")

Try omitting the -S option.

$ wc longlines.txt
      9     128     726 longlines.txt

$ less longlines.txt
WHAN that Aprille with his shoures soote The droghte of Marche hath perced to th
e roote,
And bathed every veyne in swich licour, Of which vertu engendred is the flour;
Whan Zephirus eek with his swete breeth Inspired hath in every holt and heeth
The tendre croppes, and the yonge sonne Hath in the Ram his halfe cours y-ronne,
And smale fowles maken melodye, That slepen al the night with open ye,
So priketh hem nature in hir corages: Than longen folk to goon on pilgrimages,
And palmers for to seken straunge strondes, To ferne halwes, couthe in sondry lo
ndes;
And specially, from every shires ende Of Engelond, to Caunterbury they wende,
The holy blisful martir for to seke, That hem hath holpen, whan that they were se
ke.
longlines.txt (END)

$ less -S longlines.txt
WHAN that Aprille with his shoures soote The droghte of Marche hath perced to th
And bathed every veyne in swich licour, Of which vertu engendred is the flour;
Whan Zephirus eek with his swete breeth Inspired hath in every holt and heeth
The tendre croppes, and the yonge sonne Hath in the Ram his halfe cours y-ronne,
And smale fowles maken melodye, That slepen al the night with open ye,
So priketh hem nature in hir corages: Than longen folk to goon on pilgrimages,
And palmers for to seken straunge strondes, To ferne halwes, couthe in sondry lo
And specially, from every shires ende Of Engelond, to Caunterbury they wende,
The holy blisful martir for to seke, That hem hath holpen, whan that they were s
longlines.txt (END)
3
  • 1
    Lines are not being chopped whether I put the -S or not.
    – Ram Rachum
    May 5, 2011 at 16:19
  • 1
    Either you and the man page disagree about what "chop" means or your less is broken. May 5, 2011 at 16:23
  • I think this may be an issue with the terminal emulator instead, see my top question please. May 5, 2011 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .