0

Do less textfile | col and cat textfile accomplish the same thing?

I wonder if man mysql | col -b > textfile and man mysql > textfile do the same?

3
  • Do you have an example in mind that you're asking these about?
    – slm
    Commented Sep 14, 2014 at 18:10
  • Yes, see my edit.
    – Tim
    Commented Sep 14, 2014 at 18:17
  • 1
    I would say that given you're piping the output to col -b that they're different, in the sense, that if there are any backspaces within the output, the col -b will strip them away.
    – slm
    Commented Sep 14, 2014 at 18:20

2 Answers 2

2

That's completely different, since less may do various kinds of transformation, e.g. via $LESSOPEN.

1

It's not quite the same, since when col can do something with output from less.

The important point here, less will copy input file to output if its output is not a tty. You can see in less-451 - main.c - line 222:

    /*
     * Set up terminal, etc.
     */
    if (!is_tty)
    {
        /*
         * Output is not a tty.
         * Just copy the input file(s) to output.
         */
        SET_BINARY(1);
        if (nifile() == 0)
        {
            if (edit_stdin() == 0)
                cat_file();
        } else if (edit_first() == 0)
        {
            do {
                cat_file();
            } while (edit_next(1) == 0);
        }
        quit(QUIT_OK);
    }

So, to do the same as cat file, you can:

less file | grep ^
2
  • Even if less doesn't do anything special, your less file | grep . example is wrong, as grep . will/may filter out lines that do not contain valid characters.
    – vinc17
    Commented Sep 14, 2014 at 18:40
  • @vinc17: Oh, my mistake, fixed it.
    – cuonglm
    Commented Sep 14, 2014 at 18:41

You must log in to answer this question.

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