Register
It is currently Mon Sep 01, 2014 5:24 pm

Get text output between two variables


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Sep 08, 2009 2:37 pm   

Joined: Tue Sep 08, 2009 2:27 pm
Posts: 1
Probably not the best subject line ever but not quite sure how to explain it.

Basically I need to get the text between two known words.

The command output looks something like:

Quote:
blah
blah
blah
blah
Group:
name_of_group
name_of_group
name_of_group
name_of_group
name_of_group
name_of_group
name_of_group
name_of_group
HomeDirectory: blah
blah
blah
etc ...


Using a dscl command I get all the AD Attributes of a user, and I need to get the users group info. But the number of groups there are depends on the user, and sometimes the output of the Group attribute are contained to a single line, and sometimes its multiple lines. I need a way of getting all the text between the word "Group:" and "HomeDirectory:".


Top
 Profile  
 PostPosted: Tue Sep 08, 2009 7:22 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
a clue:
Code:
awk '/Group/,/Home/ { print }'


Top
 Profile  
 PostPosted: Fri Dec 11, 2009 4:55 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 666
Location: Des Moines, Iowa
Code:
awk '/Group/,/Home/ { print }' < test.txt | tail +2 | sed '$d'


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP