Jinghao Shi
Jinghao Shi

Reputation: 1087

Line Buffered Cat

is there a way to do line-bufferd cat? For example, I want to watch a UART device, and I only want to see it's message when there is a whole line. Can I do some thing like:

cat --line-buffered /dev/crbif0rb0c0ttyS0

Thanks.

Upvotes: 1

Views: 6078

Answers (3)

bdonlan
bdonlan

Reputation: 231213

Pipe it through perl in a no-op line-buffered mode:

perl -pe 1 /dev/whatever

Upvotes: 1

Greyson
Greyson

Reputation: 3678

You can also use bash to your advantage here:

cat /dev/crbif0rb0c0ttyS0 | while read line; do echo $line; done

Since the read command reads a line at a time, it will perform the line buffering that cat does not.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798764

No, but GNU grep with --line-buffered can do this. Just search for something every line has, such as '^'.

Upvotes: 3

Related Questions