How can i cut with sed the following property to have only MAC
?
MAC evbyminsd58df
I did this but it works in the other side:
sed -e 's/^.\{1\}//'
How can i cut with sed the following property to have only MAC
?
MAC evbyminsd58df
I did this but it works in the other side:
sed -e 's/^.\{1\}//'
Just remove everything from the space:
$ echo "MAC evbyminsd58df" | sed 's/ .*//'
MAC
As you mention cut, you can use cut
selecting the first field based on space as separator:
$ echo "MAC evbyminsd58df" | cut -d" " -f1
MAC
With pure Bash, either of these:
$ read a _ <<< "MAC evbyminsd58df"
$ echo "$a"
MAC
$ echo "MAC evbyminsd58df" | { read a _; echo "$a"; }
MAC
with cut
(space as delimiter, select first field):
echo "MAC evbyminsd58df" | cut -d " " -f 1
with awk
(select print first field, space is default delimiter):
echo "MAC evbyminsd58df" | awk '{print $1}'
Use grep like below,
grep -o '^[^ ]\+' file
OR
grep -o '^[^[:space:]]\+' file
^
Asserts that we are at the start. [^[:space:]]
Negated POSIX character class which matches any character but not of a space , zero or more times.