Hi.
The other side of the coin is to extract a portion of a line. In this case we notice the string is field number 1. We can use another standard command similar to the
awk solution:
Code:
#!/usr/bin/env bash
# @(#) s1 Demonstrate extraction of field.
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) cut
set -o nounset
echo
s="43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0"
echo " Input string: $s"
echo
echo " Results:"
echo "$s" | cut -d" " -f1
exit 0
Producing:
Code:
$ ./s1
(Versions displayed with local utility "version")
FreeBSD 4.11-STABLE
GNU bash 3.1.17
cut - no version provided for /usr/bin/cut.
Input string: 43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0
Results:
43.96.199.87
cheers, drl