Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract a stanza - awk help? 1

Status
Not open for further replies.

jprabaker

Technical User
May 31, 2001
185
GB
Hi,

I have a file that I want to extract a full stanza from. The format of the file is:

daemon:
admin = true
expires = 0101000070

bin:
admin = true
expires = 0101000070

sys:
admin = true
expires = 0101000070

adm:
admin = true

uucp:
admin = true
login = false
rlogin = false
su = true

I'm guessing that awk would be the best tool, but can someone give me a few pointers?


Thanks,
John
 
Hi,

try this shell script

BEGIN script------------------

function get_stanza {
# count arguments
if [ $# -ne 1 ]
then
print "usage : $0 user_login"
return 1
fi
#seek for user_login
awk -v login="$1:" -F= \
'
{
if ( $0 == login ){
print $0;
getline
while ( NF == 2 ) {
print $0;
getline $0
}
}
} ' $PASSWORD_FILE
} # end function get_stanza

PASSWORD_FILE=/path/to/passwd

for U in user1 user2 user3
do
get_stanza $U
done
END script ---------------

Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top