16
rated 0 times
[
16]
[
0]
/ answers: 1 / hits: 77323
/ 2 Years ago, mon, november 21, 2022, 3:53:39
How do I get from this:
randomcollege-ntuser90
to this:
user90
using sed
?
More From » command-line
How do I get from this:
randomcollege-ntuser90
to this:
user90
using sed
?
I'd use a simple grep
to look for user90
:
$ echo "randomcollege-ntuser90" | grep -o user90
user90
If user90 is not constant, prefer this command:
$ echo "randomcollege-ntuser90" | grep -oP '(?<=randomcollege-nt)w+'
user90
Finally using sed
to edit the file in place:
$ sed -ri 's/randomcollege-nt(user[0-9]+)/1/' my_file
Or to match all possible user accounts:
$ sed -ri 's/randomcollege-nt(w+)/1/' my_file