How to extract fields from etc/passwd file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to extract fields from etc/passwd file?
# 1  
Old 01-28-2012
How to extract fields from etc/passwd file?

Hi!
i want to extract from /etc/passwd file,the user and user info fileds, to a another file.I've tried this:
Code:
cut -d ':' -f1 ':' -f6 < file

but cut can be used to extract olny one field and not two.
maybe with awk is this possible?
# 2  
Old 01-28-2012
cut can cut multiple fields. I.e.

Code:
cut -d: -f1,3,5 file

Or with awk:

Code:
awk -F: '{ print $1, $3 }' file

This User Gave Thanks to Scott For This Post:
# 3  
Old 01-28-2012
oh thank you very much!
# 4  
Old 01-28-2012
Hi,

Can we assign each fields to variables by the same 'awk' command??

Thanks.
# 5  
Old 01-28-2012
Hi.
Quote:
Originally Posted by strawhatluffy
...but cut can be used to extract olny one field and not two ...
As Scott noted this is not usually the case, and is contrary to every man page on cut that I have seen.

This suggests to me that you did not look at man cut or that you did not understand it.

Your best first step to becoming self-sufficient for *nix support is to cultivate the habit of looking at man pages. On some systems, additional information is available by looking at info pages, for example info cut. The man pages often are not tutorials, but, notwithstanding how good responses here here at unix.com are, man pages are certainly a better initial action to get factual answers rather than spending time composing forum posts and waiting for responses. The next step is searching, using Google, for example.

Best wishes on advancing your *nix knowledge ... cheers, drl
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

awk to extract multiple values from file and add two additional fields

In the attached file I am trying to use awk to extract multiple values and create the tab-delimited desired output. In the output R_Index is a the sequential # and Pre_Enrichment is defaulted to .. I can extract from the values to the side of the keywords, but most are above and I can not... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. UNIX for Dummies Questions & Answers

Extract user accounts and home directory from /etc/passwd.

I am trying to obtain all user accounts and their respective home directories. /etc/passwd contains the required information, but I want to filter it to only show the uid,username and home directory path. I am working on a Solaris 11 machine. I made a little headway so far, but I got stuck... (7 Replies)
Discussion started by: Hijanoqu
7 Replies

4. Shell Programming and Scripting

extract fields from a downloaded html file

I have around 100 html files and in each html file I have 5-6 such paragraphs of a company and I need to extract the Name of the company from either the one after "title" or "/company" and then the number of employees and finally the location . <div class="search_result"> <div... (1 Reply)
Discussion started by: gubbu
1 Replies

5. UNIX for Dummies Questions & Answers

passwd -S on linux- what are the fields?

I'm looking for some documentation on what the different fields mean in the output of passwd -S username: passwd -S foo foo PS 2012-03-20 0 70 3 -1 (Password set, MD5 crypt.) I think the date given is the date of the last password change, the 0 after that is the minimum password age, and... (2 Replies)
Discussion started by: Anne Neville
2 Replies

6. Shell Programming and Scripting

Cut fields from /etc/passwd file into variables?

The script must ask the user to enter the user name and check whether the user exists in /etc/passwd (you must allow the partial usernames also). If the username exists, display the details as: List of users Login Name: User ID: ... (3 Replies)
Discussion started by: nobletechnology
3 Replies

7. UNIX for Dummies Questions & Answers

extract fields from text file using delimiter!!

Hi All, I am new to unix scripting, please help me in solving this assignment.. I have a scenario, as follows: 1. i have a text file(read1.txt) with the following data sairam,123 kamal,122 etc.. 2. I have to write a unix... (6 Replies)
Discussion started by: G.K.K
6 Replies

8. UNIX for Dummies Questions & Answers

Extract some common fields from 1 file that are presnt in another file

I have 2 files FILEA 720646363*PHILIPPINES 117183970*USA 116274291*USA 107940983*USA 107395824*USA 106632425*USA 105861926*USA 105208607*USA 053077046*USA 065428026*ENGLAND FILEB 001125236 001408905 002316511 002521094 020050725 035018308 052288735 (1 Reply)
Discussion started by: unxusr123
1 Replies

9. Shell Programming and Scripting

how to extract fields for /etc/passwd

hi, i would like to extract the just name field from /etc/passwd file, and nothing else. ie grep pauline, and Pauline Fowler comes back. cheeers paul mc (6 Replies)
Discussion started by: mopimp
6 Replies

10. UNIX for Dummies Questions & Answers

Trying to extract a field from /etc/passwd file..

Hello, was looking for some help on extracting a field from the passwd file. So far I have made a copy of the passwd file and changed my rights so I can edit it. Every user's password is coded as an :x:, and my goal was to change that x to a blank, and then try to extract any user with that field... (2 Replies)
Discussion started by: xBuRnTx
2 Replies
Login or Register to Ask a Question