If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > VI / Regular Expression Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-03, 19:06
ffresh12 ffresh12 is offline
Registered User
 
Join Date: Sep 2003
Posts: 4
VI / Regular Expression Help

Hey hows it going.. I am new to Unix and working on a Solaris system. I need to take the etc/passwd file and seperate each line by the colons and then space it out evenly so all the lines form colums, so it looks something like this..

Before Example:

Donhoke:x:4454:44on Hooke:/var/adm:


After Example:

Donhoke 4454 44 Don Hooke /var/adm
dfkfgfg 1138 512 Donh fgfghhj bin/ksh


The user names start in column 0.
The user ids end in column 24.
The group ids end in column 34
The real names start in column 40
The shell starts in column 64

Please give me some help or advice.. Thanks!!
Reply With Quote
  #2 (permalink)  
Old 09-26-03, 04:31
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
awk -F":" '{printf("%-10s%-10s%-10s%-10s\n",$1,$3,$4,$5)}' /etc/passwd

Where '10' is the length of each individual column (I couldn't work out what widths you really wanted!)
Reply With Quote
  #3 (permalink)  
Old 10-06-03, 16:06
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi ffresh12.

do you need this ?

> /etc/passwd.NEW
cat /etc/passwd | awk ' BEGIN { FS=":"; OFS=":"}
{
print $0 >> "/etc/passwd.NEW"
print "User ",$1 >> "/etc/passwd.NEW"
print "User-ID ",$2 >> "/etc/passwd.NEW"
print "Group-ID ",$3 >> "/etc/passwd.NEW"
print "User Name ",$4 >> "/etc/passwd.NEW"
print "User Shell ",$5 >> "/etc/passwd.NEW"
}'

FS means the field seperator for input in awk
OFS means the output field seperator ( the default in awk is a BLANK )

That is what you get in /etc/passwd.NEW

Donhoke:4454:44on Hooke:/var/adm
User Donhoke
User-ID 4454
Group-ID 44
User Name Don Hooke
User Shell /var/adm


Greetings from Germany
Peter F.

Last edited by fla5do; 10-06-03 at 16:15.
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

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