Werewolf. Sed and Cut fun.

One of my colleagues needed to “su” into another user on our development machine. He had permission to do it, but didn’t remember target user full username, only that “ivan” was a part of it. Here is a funny commands he could use:

# "sed" example
sudo su `getent passwd | grep ivan | sed 's/\([^:]*\):.*/\1/' | head -n 1`
 
# and a much simpler "cut" example
sudo su - `getent passwd | grep ivan | cut -d : -f 1 | head -n 1`

Leave a Reply