LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-14-2014, 01:50 PM   #1
Andy_CH
LQ Newbie
 
Registered: May 2011
Posts: 5

Rep: Reputation: Disabled
tee disables grep


I've a problem with tee

cat /dev/ttyS0 | grep abc

generates exactly that what I want

cat /dev/ttyS0 | grep abc | tee logfile

Writes all lines coming from ttyS0 to the logfile.
What's wrong?

Thanks
Andy
 
Old 08-14-2014, 01:53 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Well, that IS what you are asking it to do...

The question is, what is it you WANT it to do?
 
1 members found this post helpful.
Old 08-19-2014, 03:34 AM   #3
Andy_CH
LQ Newbie
 
Registered: May 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hm - I thougt it's clear :-) Sorry


cat /dev/ttyS0 | grep abc

Gives me the output to the console -> exactly as I expect

cat /dev/ttyS0 | grep abc > logfile

Writes it to a file -> exactly as I expect


Now I want to have it in a file and on the console

But using tee, I have much more output than before

(English is definitly not my native language - I hope you understand what I mean)

Last edited by Andy_CH; 08-19-2014 at 03:35 AM.
 
Old 08-21-2014, 06:46 AM   #4
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
You were actually pretty clear the first time around. And what you describe sounds impossible.

My best guess is that you are accidently not looking at the same logfile you are writing to. Or that you are looking at "old" stuff in the logfile while current content is still buffered and not written to the file yet.

Console 1:
Code:
rw@jodel:~$ cat > fifo
Hello
this line shouldn't show
Jelly
rw@jodel:~$
Console 2:
Code:
rw@jodel:~$ cat fifo | grep ll | tee log
Hello
Jelly
rw@jodel:~$ cat log
Hello
Jelly
rw@jodel:~$
 
1 members found this post helpful.
Old 08-23-2014, 06:49 AM   #5
Andy_CH
LQ Newbie
 
Registered: May 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
After a couple of trials I have the idea, that my problem may have to do with the separator ...

cat /dev/ttyS0 > log_1
cat log_1

shows me ^M after each alpha-numeric field.

0F0509F4^M0F0608D7^M0F1E0BFF^M[BatteryManagement] Neuer Zustand: POWER_FAIL
1005FFF8^M100800000005^M070252A37B53

Only after the line starting with [BatteryManagement] (which I terminate with \n in the C-program) a new line starts.

Is there a way to handle that in my command sequence?

[Edit]
Solved!

As I thougt it was not a problem of tee itself

sudo cat /dev/ttyS0 | sed 's/\r/\n/g' | grep -i battery

Last edited by Andy_CH; 08-28-2014 at 10:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
tee alternative nenpa8lo Programming 12 01-26-2012 11:01 AM
(e)grep and tee question Vhal Linux - Newbie 7 05-27-2010 06:46 AM
tee for two JohnnyBoy123 Linux - Newbie 3 04-22-2009 07:48 PM
tee vs > or >> DotHQ Linux - General 3 08-23-2006 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration