Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [solved]Real time parsing/substitution with sed?

    Reply
    szopin | # 1 | 2011-11-23, 17:36 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by szopin; 2011-11-24 at 20:11.

     
    wnd | # 2 | 2011-11-23, 20:10 | Report

    Originally Posted by szopin View Post
    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by wnd; 2011-11-23 at 20:11. Reason: lets only run for five seconds
    The Following 3 Users Say Thank You to wnd For This Useful Post:
    reinob, szopin, vi_

     
    szopin | # 3 | 2011-11-24, 20:12 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    wnd | # 4 | 2011-11-24, 22:17 | Report

    Originally Posted by szopin View Post
    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to wnd For This Useful Post:
    reinob, szopin

     
    reinob | # 5 | 2011-11-25, 08:31 | Report

    @wnd,

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

    Edit | Forward | Quote | Quick Reply | Thanks

     
vBulletin® Version 3.8.8
Normal Logout