Bash scripting/command to change stdin?


Forum: Programming and Scripting
Topic: Bash scripting/command to change stdin?
started by: chaostic

Posted by chaostic on Jan. 25 2008,07:43
I currently have a tty input (or tail -f) that gives me:
blah blah blah *number* blah blah.
I can use sed to remove the blah blah's since they are always the same.

But what I want to do is take the input, now:
6
3
3
n

and turn it into
~~~~~~~ etc.

I can't do this with sed because sed always adds a newline to the end of any pattern space.

Also, I wouldn't need to use sed to remove the blah blahs, because I basicly want a constantly updated "~" per line of input, continuously adding to the same line.

Posted by chaostic on Jan. 25 2008,07:55
Never mind, found how to do it. I already had it in place for a different use, but here:

cat /dev/ttyu1 | grep --line-buffered "blah" | while read starvingcount; do echo -ne "~"; done;

Posted by ^thehatsrule^ on Jan. 25 2008,16:07
Quote
I can't do this with sed because sed always adds a newline to the end of any pattern space.
You can suppress the default action of printing out the pattern space with -n switch

Posted by chaostic on Jan. 26 2008,13:01
Quote (^thehatsrule^ @ Jan. 25 2008,11:07)
Quote
I can't do this with sed because sed always adds a newline to the end of any pattern space.
You can suppress the default action of printing out the pattern space with -n switch

I could do that, but then how would I get output? The biggest thing is that sed always adds a newline to the end of anything it prints out, filling the terminal buffer alot sooner then I want.

But, like I said. I figured it out, and found out about the sed -u option, which makes use a line buffer instead of its normal block buffer.

Posted by WDef on Jan. 26 2008,15:10
[Deleted]

Not sure about reading from a terminal, but the '-W interactive' option to mawk (on dsl) switches on line buffering from stdin and switches off buffering to sdout, so this(?) might work (dunno):

Code Sample
cat /dev/ttyu1 | mawk -W interactive '{printf "~"}'


I had some Perl examples above, but they probably needed to sysread and syswrite to do this unbuffered.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.