0

I have a single line of about 30000 characters (and no newline) in my clipboard. I want to put that into a file. I tried the following command in a GNOME terminal (Ubuntu 20.04):

cat > file.ext

and then pasted the line using shift+ctrl+V.

The file ended up with only 4096 characters.

I can successfully create the file by typing

gedit file.ext

and then pasting the line with ctrl+V and closing the text editor. But why can't I do it with a command-line utility like cat?

k314159
  • 445
  • cat isn't the issue. I don't know what is, but it isn't cat – Chris Davies Aug 16 '23 at 10:45
  • The Linux terminal driver / line editor is: "The maximum line length is 4096 chars (including the terminating newline character); lines longer than 4096 chars are truncated." See the linked post – ilkkachu Aug 16 '23 at 10:56
  • 1
    If you want to copy to and from the clipboard or X selection in the terminal, see man xsel. xsel can work with the primary selection, secondary selection, or the clipboard (and note that the interactions between these three and your terminal and various apps takes some getting used to). xsel can read from stdin or write to stdout. BTW, I occasionally (at least once a week or so) use xsel to copy/paste very large text selections (tens of thousands of lines - because it's much easier to pipe something into xsel -i than it is to manually select & copy it from the terminal buffer) – cas Aug 16 '23 at 14:30

1 Answers1

-2

The max line length is 4096 chars, so you can't paste 30k as you mention. What you could do is try to separate it by creating a python script that reads the line and separates it.

The maximum line length is 4096 chars (including the terminating newline character); lines longer than 4096 chars are truncated. After 4095 characters, input processing (e.g., ISIG and ECHO* processing) continues, but any input data after 4095 characters up to (but not including) any terminating newline is discarded. This ensures that the terminal can always receive more input until at least one line can be read.

  • 2
    just a repetition of the answer that was linked as duplicate, not new information. In this case, it's desirable to just leave it at the duplicate. We're not trying to maximize text on this website, we're optimizing usefulness! – Marcus Müller Aug 16 '23 at 13:09