Problems finding "fields" on the /etc/passwd file

Problem completing one of the interactive tutorials?

Moderator: drgrussell

Post Reply
medinita3586

Problems finding "fields" on the /etc/passwd file

Post by medinita3586 » Sat Dec 13, 2014 9:13 pm

Hello, maybe this is bothersome to most of you but I have no other place to go finding answers to my problems in learning this tutorial. My problem now is that I had to skip question 5 on the pipe section which asks: "sort the user ID numbers (third field) in ascending order." I feel very comfortable with the usage of the 'grep' command at this point and I have been using it with some success through all this tutorial but when I look at the /etc/passwd file, I see that there isn't any fields per se, because all the text in the lines is continuous without any columns, so there are no fields to be sorted in the file. So, is there another "/etc/passwd" file somewhere else in my file system? Or should I create the columns in the text by using the -t option?

This is getting more technical and seems that it is the learning material I have been searching for in order to become more acquainted with the Linux system.

Can anyone help me with this problem?

Thank you in advance.

rotten

Re: Problems finding "fields" on the /etc/passwd file

Post by rotten » Wed Dec 17, 2014 8:15 pm

Greetings,

this question is all about the way you build your sort command. There's no need using grep here :!:
...but when I look at the /etc/passwd file, I see that there isn't any fields per se, because all the text in the lines is continuous without any columns, so there are no fields to be sorted in the file...
From sort's man page:

Code: Select all

    -t, --field-separator=SEP
              use SEP instead of non-blank to blank transition
A field separator can be any character:
- a white space " "
- a pipe "|"
- a semicolon ";"
- a colon ":"

The following example took from http://en.wikipedia.org/wiki/Delimiter uses a comma as a field separator:

Code: Select all

fname,lname,age,salary
nancy,davolio,33,$30000
erin,borakova,28,$25250
tony,raphael,35,$28700
Take a look at the passwd file again: which character (field separator) should you use with the "-t" option? 8)
So, is there another "/etc/passwd" file somewhere else in my file system? Or should I create the columns in the text by using the -t option?
If you run "ls -l /etc" do you see two "/etc/passwd" files? :roll:

medinita3586

Re: Problems finding "fields" on the /etc/passwd file

Post by medinita3586 » Thu Dec 18, 2014 2:34 am

Okay now, this is getting pretty interesting and yes, when I do ls -l into /etc/passwd, I see that there are two passwd files but one has a - at the end but now I see what the real problem was on my part, I just wasn't aware that all the punctuation marks are considered "field separators" and when I used the "sort -t: -k3n /etc/passwd command, Bingo! It worked! Thank you very much, really.

Now I see that Linux is a very detailed little devil and I need to keep learning.

Thanks again

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest