maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   [solved]Real time parsing/substitution with sed? (https://talk.maemo.org/showthread.php?t=80307)

szopin 2011-11-23 17:36

[solved]Real time parsing/substitution with sed?
 
Not sure if this is possible with sed, but after a bit of googling I believe this is the right tool. I am trying to replace MAC addresses of my devices with human-friendly names. I created a file with 's/MAC/Laptop/g' lines and for cat it works:

cat file.csv | sed -f list (this replaces mac addresses as expected)

but real-time output doesn't:

airodump-ng wlan0 | sed -f list (no substitution takes place)

Can this be achieved with sed?

wnd 2011-11-23 20:10

Re: Real time parsing/substitution with sed?
 
Quote:

Originally Posted by szopin (Post 1127965)
but real-time output doesn't:

airodump-ng wlan0 | sed -f list (no substitution takes place)

Can this be achieved with sed?

This doesn't have anything to do with sed. sed cannot edit your data if it doesn't get it. Instead, this has everything to do with output buffering. Try the following to commands (also without pipe to sed) and you'll iunderstand what I mean.

Code:

perl -e '$| = 0; foreach (1..5) { print "$_\n"; sleep(1); }' | sed 's/2/XYZZY/; s/4/foobar/'
perl -e '$| = 1; foreach (1..5) { print "$_\n"; sleep(1); }' | sed 's/2/XYZZY/; s/4/foobar/'

In other words, you'll have do disable output buffering from airodump-ng or whatever application you use to generate the data.

szopin 2011-11-24 20:12

Re: [solved]Real time parsing/substitution with sed?
 
Courtesy of Reddit user xaoq:

airodump-ng wlan0 2>&1 | sed -f list.txt

explanation: airodump-ng apparently dumps data into stderr, not stdout. Hence the redirect stderr -> stdout.

wnd 2011-11-24 22:17

Re: [solved]Real time parsing/substitution with sed?
 
Quote:

Originally Posted by szopin (Post 1127965)
but real-time output doesn't:

airodump-ng wlan0 | sed -f list (no substitution takes place)

I feel so dumb. I somehow read this as "substitution doesn't work in real time". My mistake.

reinob 2011-11-25 08:31

Re: [solved]Real time parsing/substitution with sed?
 
@wnd,

Still. Your reply was spot on, at least in the general case.


All times are GMT. The time now is 01:41.

vBulletin® Version 3.8.8