Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Bash scripting/command to change stdin?, turn multiple lines to one line.< Next Oldest | Next Newest >
chaostic Offline





Group: Members
Posts: 328
Joined: Mar. 2005
Posted: Jan. 25 2008,07:43 QUOTE

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.
Back to top
Profile PM 
chaostic Offline





Group: Members
Posts: 328
Joined: Mar. 2005
Posted: Jan. 25 2008,07:55 QUOTE

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;
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 25 2008,16:07 QUOTE

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
Back to top
Profile PM 
chaostic Offline





Group: Members
Posts: 328
Joined: Mar. 2005
Posted: Jan. 26 2008,13:01 QUOTE

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.
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Jan. 26 2008,15:10 QUOTE

[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.
Back to top
Profile PM 
4 replies since Jan. 25 2008,07:43 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Bash scripting/command to change stdin?

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code