I have an example /etc/passwd file like this:
tom:x:1000:1000:Work:/home/tom:/bin/bash
george:x:1000:1000:Work:/home/george:/bin/bash
bla:x:1000:1000:Work:/home/bla:/bin/bash
boo:x:1000:1000:Work:/home/boo:/bin/bash
bee:x:1000:1000:Work:/root/list:/bin/bash
I'm trying to list all users with a home folder in /home/
.
I wrote
cat ~/Desktop/e.txt |awk -F ":" '{if ($6 ~/^/home/) print $1;}'
where e.txt is the text I copied here.
I understand there is a problem with the backslash which is an escape character, but how do I fix it so I can list them in one line of a command?
Best Answer
You may escape forward slashes as shown below:
Another trick would be using complex field separator:
-F'[:/]'
- treat both:
and/
to be a field separator