![]() ![]() If you're doing more complicated matches or extractions (usually with awk), -o is essential for a clean script, so for the sake of consistency and a common pattern, I always use it.Įdit: Updating 10 years later: ip now has the -j flag for JSON output, and when combined with jq, it provides a more robust and readable command pipeline: ip -j link show dev eth0 | jq -r '.address' You don't actually need the -o (oneline) option to ip, but I prefer to use it when extracting network information since I find it cleaner having one record per line. sed is traditionally used for that but I find the perl-style zero-width assertions clearer than a sed substitution command. ![]() It's modern in that ifconfig has long been deprecated in favour of ip from the iproute2 package, and that grep has the -P option for perl regular expressions for the zero-width positive look-behind assertion. Here's a modern Linux method: ip -o link show dev eth0 | grep -Po 'ether \K*' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |