Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu User (http://www.linux-archive.org/ubuntu-user/)
-   -   BASH redirect & grep -v help needed (http://www.linux-archive.org/ubuntu-user/248217-bash-redirect-grep-v-help-needed.html)

dave selby 02-18-2009 07:44 PM

BASH redirect & grep -v help needed
 
Hi All,

I am trying to get the standard output and error streams to be
filtered so that any output with the string 'saved as' is discarded
and the rest is appended to /home/dave/kmotion2/www/motion_output
Me and BASH just do not get on, I have tried

motion -c /home/dave/kmotion2/core/motion_conf/motion.conf &> | grep
-v 'saved as' >> /home/dave/kmotion2/www/motion_output
bash: syntax error near unexpected token `|'

Any idea how to make this work

Cheers

Dave

--

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Smoot Carl-Mitchell 02-18-2009 07:57 PM

BASH redirect & grep -v help needed
 
On Wed, 2009-02-18 at 20:44 +0000, dave selby wrote:
> Hi All,
>
> I am trying to get the standard output and error streams to be
> filtered so that any output with the string 'saved as' is discarded
> and the rest is appended to /home/dave/kmotion2/www/motion_output
> Me and BASH just do not get on, I have tried
>
> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf &> | grep
> -v 'saved as' >> /home/dave/kmotion2/www/motion_output
> bash: syntax error near unexpected token `|'
>
> Any idea how to make this work

motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
-v 'saved as' >> /home/dave/kmotion2/www/motion_output

This will pipe both the stdout and stderr through grep. e.g. redirect
stderr (file descriptor 2) to file descriptor 1 (stdout).
--
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot@tic.com
+1 480 922 7313
cell: +1 602 421 9005

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

dave selby 02-18-2009 08:12 PM

BASH redirect & grep -v help needed
 
> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
> -v 'saved as' >> /home/dave/kmotion2/www/motion_output
>
> This will pipe both the stdout and stderr through grep. e.g. redirect
> stderr (file descriptor 2) to file descriptor 1 (stdout).

Many thanks :) Still having a bit of trouble though - have slightly
changed the code

dave@main-system:~$ motion -c
/home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep -v 'saved
to'
[0] Processing thread 0 - config file
/home/dave/kmotion2/core/motion_conf/motion.conf
[0] Processing config file /home/dave/kmotion2/core/motion_conf/thread01.conf
[0] Processing config file /home/dave/kmotion2/core/motion_conf/thread02.conf
[0] Motion 3.2.9 Started
[0] ffmpeg LIBAVCODEC_BUILD 3352064 LIBAVFORMAT_BUILD 3344896
[0] Thread 1 is from /home/dave/kmotion2/core/motion_conf/thread01.conf
[1] Thread 1 started
[1] cap.driver: "uvcvideo"
[1] cap.card: "UVC Camera (046d:08cc)"
[1] cap.bus_info: "0000:00:10.4"
[1] cap.capabilities=0x04000001
[1] - VIDEO_CAPTURE
[1] - STREAMING
[1] Supported palettes:
[1] 0: MJPG (MJPEG)
[1] 1: YUYV (YUV 4:2:2 (YUYV))
[0] Thread 2 is from /home/dave/kmotion2/core/motion_conf/thread02.conf
[2] Thread 2 started
[0] motion-httpd/3.2.9 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] Test palette YUYV (352x288)
[1] Using palette YUYV (352x288) bytesperlines 704 sizeimage 202752
colorspace 00000008
[1] found control 0x00980900, "Brightness", range 0,255
[1] "Brightness", default 127, current 127
[1] found control 0x00980901, "Contrast", range 0,255
[1] "Contrast", default 32, current 32
[1] found control 0x00980902, "Saturation", range 0,255
[1] "Saturation", default 32, current 32
[1] found control 0x00980913, "Gain", range 0,255
[1] "Gain", default 0, current 0
[1] found control 0x08000000, "Backlight Compensation", range 0,2
[1] "Backlight Compensation", default 1, current 1
[1] found control 0x08000001, "Power Line Frequency", range 0,2
[1] "Power Line Frequency", default 2, current 2
[1] mmap information:
[1] frames=4
[1] 0 length=202752
[1] 1 length=202752
[1] 2 length=202752
[1] 3 length=202752
[1] Using V4L2

Thats what I want outputed to a file

dave@main-system:~$
dave@main-system:~$
dave@main-system:~$
dave@main-system:~$ motion -c
/home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep -v 'saved
to' >> xxx.out

dave@main-system:~$
dave@main-system:~$
dave@main-system:~$ cat xxx.out
dave@main-system:~$

So any idea why xxx.out contains zsip instead of the above ?

Cheers

Dave

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Smoot Carl-Mitchell 02-18-2009 08:27 PM

BASH redirect & grep -v help needed
 
On Wed, 2009-02-18 at 21:12 +0000, dave selby wrote:

> dave@main-system:~$ motion -c
> /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep -v 'saved
> to' >> xxx.out
>
> dave@main-system:~$
> dave@main-system:~$
> dave@main-system:~$ cat xxx.out
> dave@main-system:~$
>
> So any idea why xxx.out contains zsip instead of the above ?

No idea. What happens without the stderr redirection?
--
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot@tic.com
+1 480 922 7313
cell: +1 602 421 9005

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

dave selby 02-18-2009 08:34 PM

BASH redirect & grep -v help needed
 
>> So any idea why xxx.out contains zsip instead of the above ?
>
> No idea. What happens without the stderr redirection?

motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
-v 'saved to'

works a treat. 'motion' starts, outputs and keeps running and I have
to ctrl-c to stop it.

motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
-v 'saved to' >> xxx.out

outputs nothing, but zip in xxx.out

I am wondering if the output to the BASH shell is 'instant' but the
output to >> is only processed on 'motion' ending
in some way ?

Dave








--

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

dave selby 02-18-2009 08:37 PM

BASH redirect & grep -v help needed
 
Interesting ... after a few mins suddenly xxx.out is filled ?!??

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

John Hubbard 02-18-2009 09:33 PM

BASH redirect & grep -v help needed
 
dave selby wrote:
> Hi All,
>
> I am trying to get the standard output and error streams to be
> filtered so that any output with the string 'saved as' is discarded
> and the rest is appended to /home/dave/kmotion2/www/motion_output
> Me and BASH just do not get on, I have tried
>
> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf &> | grep
> -v 'saved as' >> /home/dave/kmotion2/www/motion_output
> bash: syntax error near unexpected token `|'
>
>
This is kind of a work around but try making a script called myMotion
#!/bin/sh
motion -c /home/dave/kmotion2/core/motion_conf/motion.conf | grep -v
'saved as' >> /home/dave/kmotion2/www/motion_output

Then call myMotion to run the command. This should be especially useful
since you don't have to type in that long command every time you restart
the system.


--
-john

To be or not to be, that is the question
2b || !2b
(0b10)*(0b1100010) || !(0b10)*(0b1100010)
0b11000100 || !0b11000100
0b11000100 || 0b00111011
0b11111111
255, that is the answer.



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

Smoot Carl-Mitchell 02-18-2009 09:55 PM

BASH redirect & grep -v help needed
 
On Wed, 2009-02-18 at 21:34 +0000, dave selby wrote:
> >> So any idea why xxx.out contains zsip instead of the above ?
> >
> > No idea. What happens without the stderr redirection?
>
> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
> -v 'saved to'
>
> works a treat. 'motion' starts, outputs and keeps running and I have
> to ctrl-c to stop it.
>
> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
> -v 'saved to' >> xxx.out
>
> outputs nothing, but zip in xxx.out
>
> I am wondering if the output to the BASH shell is 'instant' but the
> output to >> is only processed on 'motion' ending
> in some way ?

Are you saying "motion -c" has continuous output? If that is the case
then you are seeing I/O buffering side effects. Try adding
--line-buffered to the grep command. That will flush the output buffer
after each line.
--
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot@tic.com
+1 480 922 7313
cell: +1 602 421 9005

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

dave selby 02-20-2009 08:29 PM

BASH redirect & grep -v help needed
 
2009/2/18 Smoot Carl-Mitchell <smoot@tic.com>:
> On Wed, 2009-02-18 at 21:34 +0000, dave selby wrote:
>> >> So any idea why xxx.out contains zsip instead of the above ?
>> >
>> > No idea. What happens without the stderr redirection?
>>
>> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
>> -v 'saved to'
>>
>> works a treat. 'motion' starts, outputs and keeps running and I have
>> to ctrl-c to stop it.
>>
>> motion -c /home/dave/kmotion2/core/motion_conf/motion.conf 2>&1 | grep
>> -v 'saved to' >> xxx.out
>>
>> outputs nothing, but zip in xxx.out
>>
>> I am wondering if the output to the BASH shell is 'instant' but the
>> output to >> is only processed on 'motion' ending
>> in some way ?
>
> Are you saying "motion -c" has continuous output?

It appears to have.

If that is the case
> then you are seeing I/O buffering side effects. Try adding
> --line-buffered to the grep command. That will flush the output buffer
> after each line.

OK I did not realize grep could do this. Many thanks, Sorry for the
delay, work related

Cheers

Dave



> Smoot Carl-Mitchell
> Computer Systems and
> Network Consultant
> smoot@tic.com
> +1 480 922 7313
> cell: +1 602 421 9005
>
> --
> ubuntu-users mailing list
> ubuntu-users@lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>



--

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users


All times are GMT. The time now is 11:04 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.