Get first word of a line with sed
3 answers
Just remove everything from the space:
$ echo "MAC evbyminsd58df" | sed 's/ .*//'
MAC
As you say, you can use cut
to select the first field based on space as separator:
$ echo "MAC evbyminsd58df" | cut -d" " -f1
MAC
With pure Bash, any of these:
$ read a _ <<< "MAC evbyminsd58df"
$ echo "$a"
MAC
$ echo "MAC evbyminsd58df" | { read a _; echo "$a"; }
MAC
+9
source to share