BashScripts.org
http://bashscripts.org/forum/

Get text output between two variables
http://bashscripts.org/forum/viewtopic.php?f=21&t=886
Page 1 of 1

Author:  AndrewFriend [ Tue Sep 08, 2009 2:37 pm ]
Post subject:  Get text output between two variables

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:".

Author:  Watael [ Tue Sep 08, 2009 7:22 pm ]
Post subject:  Re: Get text output between two variables

a clue:
Code:
awk '/Group/,/Home/ { print }'

Author:  crouse [ Fri Dec 11, 2009 4:55 pm ]
Post subject:  Re: Get text output between two variables

Code:
awk '/Group/,/Home/ { print }' < test.txt | tail +2 | sed '$d'

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com