On 3/24/02 at 2:15 PM, Chad Carr <[EMAIL PROTECTED]> wrote: > I am attempting to port freeswan scripts that use ifconfig > and awk to use iproute and sed instead. I am posting > these modifications to get input on better ways of doing > things, since I do believe that there are probably at > least 40-50 better ways to do it than I have come up with. > > So far: > > # get the physical device that leads to the default gateway
> # becomes this without netstat or awk > ip route | sed -e '/^default/!d' -e 's/^.* ([^ ]*) $/\1/' ip route | sed -n '/^default/s/^.* ([^ ]*).*$/\1/p' > and: > > # set up some vars pertaining to $phys > # becomes (something like) this without ifconfig or awk > eval `ip addr show dev $phys | sed -e '/^ *inet/!d' -e 's/^ *inet \(.*\)\/\(.*\) > \(.*\) \(.*\) \(.*\) \(.*\) \(.*\)/addr=\1;mask=\2;type=\3;otheraddr=\4;/'` > # of course, the type and mask are not the right format eval $(ip addr show dev $phys | sed -n ' /^ *inet/s/^ *inet \(.*\) \(.*\) \(.*\) \(.*\)/addr=\1 mask=\2 type=\3 other=\4/p') > Please let me know if this way of doing things is > completely braindead or not. Not brain dead at all. Some notes: 1. With the "eval", you need to have no ";" (semicolons) in the string or it will come out acting like a separator (with an error of "mask=XXXXX: not found" 2. sed doesn't generally need -e options today. 3. The sequence: sed '/foo/!d; s/xxxx/zzzzz/' ...is equivalent to... sed -n '/foo/s/xxxx/zzzzz/p' ...this might be faster; seems clearer to me (and possibly to other sed users). 4. GNU sed allows multiple commands: sed '/foo/!d; s/xxx/zzz/' ...works fine (note ";") -- returns work too. > Coming from a perl background, I am not afraid of a regex or two, even > complicated ones. I just am so unfamiliar with sed, I don't even have any > frame of reference. > > Thanks in advance for your assistance. > > > --------------------------------------------------------------------------- > Chad Carr [EMAIL PROTECTED] > --------------------------------------------------------------------------- -- David Douthitt UNIX Systems Administrator HP-UX, Unixware, Linux [EMAIL PROTECTED] _______________________________________________ Leaf-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-devel