4

I want to execute yum list installed > file.txt and output results to a txt file which is NOT wrapped by X characters. At least, I want to be able to control "width" of this output buffer.

I know that stty columns 250 will set column width of my console window to 250 characters but how do I accomplish this when I redirect output to a file?

This has certainly been asked before but I just could not find an answer...

Edit:

This seems to be a yum thing since ps aux > ps.txt works just fine. With yum, file is limited to only 80 characters so I'm adding yum tag. I have no idea how can yum give different output on screen and on the file while other programs work just fine (also note that I'm a beginner in bash).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
bokibeg
  • 2,081
  • 16
  • 23
  • Hm. A little C prog, an awk or sed script... – Peter - Reinstate Monica Apr 15 '15 at 11:42
  • `yum list installed > file.txt` is not being wrapped at all. yum does play with columns though to get nicely fitting output though but that doesn't have to do with your terminal or anything. – Etan Reisner Apr 15 '15 at 11:45
  • @Etan I edited my question with extra details. – bokibeg Apr 15 '15 at 11:55
  • 1
    yum tries to find out the size of the terminal (resize it and you'll see that) but when piping to a file it can't do that correctly and just uses `80` it looks like. – Etan Reisner Apr 15 '15 at 13:21
  • 1
    @EtanReisner Oh, I totally misunderstood the question. He wants *no wrap* :-). Thanks for the clarification. I'll also remove my answer since it isn't one. – Peter - Reinstate Monica Apr 15 '15 at 13:29
  • 1
    He wants to undo the built-in yum "wrapping" (not line wrapping exactly more column fitting by line insertion) and yeah the problem here is in undoing what yum did (or convincing it not to do that which doesn't seem possible). – Etan Reisner Apr 15 '15 at 13:32

2 Answers2

3

I think you have two options.

  1. Edit the yum source (http://yum.baseurl.org/download/3.4/yum-3.4.3.tar.gz). The 80 is hard coded in output.py, line 53.

  2. It's probably doable to make yum believe it is writing to a terminal. Whether -- and if, how -- it is possible to set the number of columns for that fake terminal I am not sure of. One thing that pops up is Linux' unbuffer (cf. Piping data to Linux program which expects a TTY (terminal)). Perhaps a little self written unbuffer-like C wrapper may use a pty and have more control over it; even bash may have an esoteric feature for that.

Community
  • 1
  • 1
Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
  • You're right, it's hard coded in output.py! I will play around with option 2 as well but at least I have something now :). – bokibeg Apr 15 '15 at 15:06
3

I stumbled across a hackish way to do this using screen:

screen -L yum --color=never list installed

This will result in a file called screenlog.0 containing the output, and yum will think it is outputting to a TTY with the same width as your current screen.

harmic
  • 28,606
  • 5
  • 67
  • 91