Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > cut and paste passwd file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-04, 22:08
Daryl Lim Daryl Lim is offline
Registered User
 
Join Date: May 2004
Posts: 11
cut and paste passwd file

Hi all,

How do i do the following using cut & paste:

create a file from /etc/passwd in a format:

userid:username:groupid

e.g:
0:root:0
1:bin:1
2:daemon:2
3:adm:4

i tried to cut the userid field with "cut -f 3 -d: > file1" but got the userid without ":" (deliminator) for making the first column in the new file.

Thank you.

Daryl
Reply With Quote
  #2 (permalink)  
Old 06-06-04, 09:09
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi Daryl Lim,
I dont understand your question exactly. What is the output in file1 you want to have ?
__________________
Greetings from germany
Peter F.
Reply With Quote
  #3 (permalink)  
Old 06-06-04, 11:19
Daryl Lim Daryl Lim is offline
Registered User
 
Join Date: May 2004
Posts: 11
Hi Peter,

I would like my file1 to be in the format of :

userid:username:groupid



regards,
Daryl
Reply With Quote
  #4 (permalink)  
Old 06-06-04, 12:58
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi,
do you mean this ?

# this is an example from my passwd
# support:x:1301:200upport-User:/usr2/support:/bin/sh
# guest:x:1303:50:GastUser:/usr/guest:/bin/sh

cat /etc/passwd | awk ' BEGIN { FS=":" }
{
print $3":"$1":"$4 > "file1"
}'

# and this will be the output in file1
# 1301:support:200
# 1303:guest:50
__________________
Greetings from germany
Peter F.
Reply With Quote
  #5 (permalink)  
Old 06-06-04, 14:06
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Quote:
Originally Posted by Daryl Lim
i tried to cut the userid field with "cut -f 3 -d: > file1" but got the userid without ":" (deliminator) for making the first column in the new file.

Hi, I read your question again and now I think to understand your problem.

you get the delimiter ":" in file1 when you specify the second and more fields like this:"cut -f 3,4... -d: > file1"

In your example is only one field. It is not necessary to use delimiters if you have only one field.
__________________
Greetings from germany
Peter F.
Reply With Quote
  #6 (permalink)  
Old 06-07-04, 16:49
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 240
You can use

cat /etc/passwd | awk -F: '{print $1":"$2":"3}'

where $fields will represend the order of the field in password file, separated by :

cheers
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On