0

I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.

I have a config file with lines like:

u:TestUser:rw:/home/temp/testFolder

I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.

The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.

1
  • awk -F":" '{print $2}' config_file would give you TestUser. Commented Jan 3, 2019 at 10:19

1 Answer 1

0

You need to "cut" the text between delimiters. A job for cut:

cut -d: -f2 /etc/passwd
  • -d: - set's the delimeter to : (default is tab)
  • -f2 - will make cut print only the second field frim the file - ie. username

But to check if a user exists on a system, see superuser - Find out if user name exists and use id command.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.