LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-05-2006, 04:03 PM   #1
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Rep: Reputation: 15
cat to grep to textfile?


Hi,


I am goofing around with a GPS unit a purchased the other day. I have it connected to the PC via a serial cable. It is using ttyS0. If I
Code:
"cat /dev/ttyS0"
I see the repetitive output of serial data on the terminal:

Code:
$GPRMC,170014,V,4050.5741,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*27
$GPRMB,V,,,,,,,,,,,,A,S*0E
$GPGGA,170014,4050.5741,N,08022.1031,W,8,09,2.0,370.8,M,-33.6,M,,*7B
$GPGSA,A,3,01,06,07,14,16,20,23,25,30,,,,3.6,2.0,3.0*33
$GPGSV,3,1,09,01,63,114,49,06,20,065,41,07,22,133,42,14,17,125,40*7C
$GPGLL,4050.5741,N,08022.1031,W,170014,V,S*5E
$GPBOD,,T,,M,,*47
$GPVTG,0.0,T,9.0,M,17.4,N,32.2,K*46
$PGRME,15.0,M,22.5,M,27.0,M*1A
$PGRMZ,1216,f,3*2F
$PGRMM,WGS 84*06
$GPRTE,1,1,c,*37
$GPRMC,170016,V,4050.5837,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2B
$GPRMB,V,,,,,,,,,,,,A,S*0E
$GPGGA,170016,4050.5837,N,08022.1031,W,8,09,2.0,370.8,M,-33.6,M,,*77
$GPGSA,A,3,01,06,07,14,16,20,23,25,30,,,,3.6,2.0,3.0*33
$GPGSV,3,2,09,16
If I
Code:
"cat /dev/ttyS0 |  grep GPRMC"
I see:

Code:
$GPRMC,165548,V,4049.2892,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*21
$GPRMC,165550,V,4049.2988,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*22
$GPRMC,165552,V,4049.3085,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*25
$GPRMC,165554,V,4049.3181,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*26
$GPRMC,165556,V,4049.3278,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*21
$GPRMC,165558,V,4049.3375,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*23
$GPRMC,165600,V,4049.3471,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2E
$GPRMC,165602,V,4049.3568,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*25
$GPRMC,165604,V,4049.3664,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2C
$GPRMC,165606,V,4049.3761,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2A
$GPRMC,165608,V,4049.3858,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*21
$GPRMC,165610,V,4049.3954,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*25
$GPRMC,165612,V,4049.4051,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2C
$GPRMC,165614,V,4049.4147,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2C
$GPRMC,165616,V,4049.4244,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2E
$GPRMC,165618,V,4049.4341,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*24
$GPRMC,165620,V,4049.4437,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*29
$GPRMC,165622,V,4049.4534,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*29
$GPRMC,165624,V,4049.4631,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*29
$GPRMC,165626,V,4049.4727,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2D
$GPRMC,165628,V,4049.4824,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2F
$GPRMC,165630,V,4049.4920,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*23
$GPRMC,165632,V,4049.5017,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*2D
$GPRMC,165634,V,4049.5114,N,08022.1031,W,17.4,0.0,030906,9.0,W,S*29
What I would like to do is get this data which flows continously into a file. If I do
Code:
"cat /dev/ttyS0 | grep GPRMC >> /home/allen/gps.txt"
it creates the file but enters nothing into it.

where if I
Code:
"cat /dev/ttyS0 >> /home/allen/gps.txt"
it continously updates the file with new info but more info than I want. Where am I going wrong?

thanks.
 
Old 09-05-2006, 04:23 PM   #2
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Original Poster
Rep: Reputation: 15
Solved

I must use the --line-buffered switch with grep to produce the correct output.

As tfm says


thanks
 
Old 09-05-2006, 04:23 PM   #3
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
ttyS0 is a block file. In other words, it is not a regular file but a file which points to a hardware device. I think grep only works with character files and not block files.
 
Old 09-05-2006, 04:25 PM   #4
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Original Poster
Rep: Reputation: 15
thanks

thanks for your reply ramram
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Invalid or incomplete multibyte.." using cat textfile | mailx recipient@domain pargilo Linux - Software 0 04-01-2006 06:58 AM
cat [file] | grep --- trouble bob_man_uk Linux - General 12 03-10-2006 07:05 AM
Question About Cat And Grep George2 Linux - Software 10 03-09-2006 04:33 AM
bash: how to edit cat <filename> | grep <keyword> feature? sirpelidor Linux - Software 2 06-20-2005 03:00 PM
output to a file - cat? grep? Godsmacker777 Linux - Newbie 6 12-08-2004 11:06 AM


All times are GMT -5. The time now is 06:34 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration