You are not logged in.

#1 2009-06-12 01:45:29

fflarex
Member
Registered: 2007-09-15
Posts: 466

[SOLVED] newline appended to clipboard selection...

I have a small script that (among other things) reads text from a file and puts it in the primary clipboard using xclip. Problem is, there is an extra newline character (or at least I think that's what it is) which is appended to the selection which causes problems when pasting into a terminal. I can't get rid of it and I don't know where the problem is!

The offending line is as simple as:

cat $FILE | xclip

Where $FILE definitely does not contain a newline. I tried all sorts of sed filters before I remembered that sed only works on one line at a time, then I tried using head, and finally I gave tr a shot to restrict the characters that go through. Nothing has worked so far. Help?

Last edited by fflarex (2009-06-13 20:46:39)

Offline

#2 2009-06-12 03:01:15

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: [SOLVED] newline appended to clipboard selection...

You can try something like:

echo -en $FILE | xclip

Offline

#3 2009-06-12 03:05:46

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] newline appended to clipboard selection...

Except that echo takes strings for arguments, not files.

Offline

#4 2009-06-13 20:47:21

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] newline appended to clipboard selection...

Solved it by piping through this first:

tr -d '\n'

Offline

#5 2009-06-13 21:03:58

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] newline appended to clipboard selection...

fflarex wrote:

I tried using head

Including "cat <file> | head -n -1 | xclip"?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#6 2009-06-13 21:28:07

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: [SOLVED] newline appended to clipboard selection...

I didn't use head like that, but I tried it just now and all it did was clear my selection (or copy a null character, or something like that).

Offline

#7 2009-06-13 21:32:46

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] newline appended to clipboard selection...

Hmmm, maybe it needs to be "-n-1", or "--lines=-1".

Meh, whatever, you've already found a working solution.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB