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? Commented Sep 14, 2014 at 18:10
  • Yes, see my edit. 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. 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. Commented Sep 14, 2014 at 18:40
  • @vinc17: Oh, my mistake, fixed it. Commented Sep 14, 2014 at 18:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.