1

I have below command which output the result as newlines in every key press. I don't want it to output to file as new lines instead I want it to send it to file without linefeeds.

 stdbuf -o0 xinput test 11 >out

Is it possible?

1
  • Please tell us what exactly do you want. Because stdbuf -o0 xinput test 11, output nothing for me. I though you know what you are doing.
    – c0rp
    Dec 24, 2013 at 18:27

2 Answers 2

2

Try add echo -n

stdbuf -o0 xinput test 11 | xargs echo -n > out

Update

As i understand from your comment, you want not just remove linefeed, but also output log on every keypress using xinput.

First check all input devices:

   c0rp@c0rp:~$ xinput --list

This is a list of all available input devices

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ETPS/2 Elantech Touchpad                  id=13   [slave  pointer  (2)]
⎜   ↳ RAPOO RAPOO 2.4G Wireless Device          id=10   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Video Bus                                 id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Asus WMI hotkeys                          id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=12   [slave  keyboard (3)]
    ↳ RAPOO RAPOO 2.4G Wireless Device          id=14   [slave  keyboard (3)]
    ↳ USB2.0 HD UVC WebCam                      id=15   [slave  keyboard (3)]

Now if you want to test device, use test key, and as parameter use id from second column.

For example, i use wireless keyboard, id=14:

xinput --test 14

Here is output:

key press   42 
key press   43 
key release 43 
key release 42 
key press   44 

And finaly what you want is...

Sorry, on this step i realize that xinput cannot redirect stdout or stderr, it just buffered. Proof link.

So the only way to do what you want using xinput is:

Write xinput to a file xinput test 11 > out, then substitute all newlines using tr

tr -d '\n' < yourfile.txt

or if it doesn't work use same for DOS/Windows line endings

tr -d "\n\r" < yourfile.txt
3
  • I don't know why, it doesn't write to file. Text output file is empty.
    – kenn
    Dec 24, 2013 at 17:50
  • I update answer
    – c0rp
    Dec 24, 2013 at 19:06
  • Thank you for your comment, I already knew that, I want to know if it's possible while piping out to file. You say it's not possible. I think I must resort to your last solution. Thanks.
    – kenn
    Dec 24, 2013 at 19:40
0

You should be able to either pipe it though tr or run tr on the final file. You can either replace the new lines with spaces

tr '\n' ' '

Or delete them all together

tr -d '\n'

For example:

stdbuf -o0 xinput test 11 | tr -d '\n' >out
3
  • I tried your command, it doesn't write to file. Text output file is empty.
    – kenn
    Dec 24, 2013 at 17:49
  • and without the tr you are sure you get an output exactly as you typed it above? As the tr should just remove new lines. Dec 24, 2013 at 17:56
  • Yes this stdbuf -o0 xinput test 11 >out outputs to file but not with this stdbuf -o0 xinput test 11 | tr -d '\n' >out
    – kenn
    Dec 24, 2013 at 19:32

You must log in to answer this question.

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