0

I'm using the command grep in Linux to get a specific information from my output file, but I don't know why does not copy to the file.

When I use the command like that, it works

udevadm monitor --env | grep "ACTION"
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove
ACTION=remove

But, when I use the command like this, it does not copy to the "output.txt"

udevadm monitor --env | grep "ACTION" >> output.txt
Binarian
  • 12,296
  • 8
  • 53
  • 84
Machete
  • 13
  • 4
  • This is because of buffering in the redirection, see [this question](http://stackoverflow.com/q/13858912/1331399) to see how to get around it. Short answer: add the `--line-buffered` option to the `grep` command. – Thor Jun 11 '14 at 09:13
  • @ Thor thanks it's working now ...i just add the "--line-buffered" option like this , and it's working udevadm monitor --env | grep --line-buffered "ACTION" >> file.txt – Machete Jun 11 '14 at 09:22

2 Answers2

1

Try :

udevadm monitor --env >> file ; cat file | grep "ACTION" >> result 

tell me about file and result.

Dinou
  • 51
  • 1
  • 6
  • @ Dinou ..i used you're command, the two files are created ...in the first "file" i get all the information of the "udevadm monitor", but in the second file "result" nothing was copied to this file. – Machete Jun 11 '14 at 09:14
  • Can you type : `ll result` to know about the files rights... – Dinou Jun 11 '14 at 09:34
0

The command is correct. You must find the filtered lines in the end of output.txt. You can add tee between to see what is copied.

udevadm monitor --env | grep "ACTION" | tee >> output.txt
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144