If you type id user_name
you get uid=500(user_name)
.
How can I use sed
to get everything between the =
and (
so you get 500
?
I have sed -n ā/=/,/(/pā
.
If you type id user_name
you get uid=500(user_name)
.
How can I use sed
to get everything between the =
and (
so you get 500
?
I have sed -n ā/=/,/(/pā
.
You can group the number 500
- or any integer value, for that matter - and return it with sed 's/^uid=\([0-9]*\).*/\1/'
.
@Rfroes87 provided a fine solution in a comment - sed 's/^uid=([0-9]*).*/\1/'
But you can do it a lot of ways that don't involve another process.
You might be able to just use something like $UID
or $uidalready present - check your env with
set`.
You can use read
-
IFS='=(' read x myUID x <<< $(id)
Or you could use parameter parsing in steps -
myUID="$(id)"
myUID="${myUID#*=}"
myUID="${myUID%%(*}"