bash bash bash
August 8, 2006 1:03 PM
Subscribe
Calling all bash/nix gurus.. please help me!
I have a list of users that I'm trying to parse and convert into a html-friendly format, surrounding them around <option> tags so I can put them in an HTML select form.
I'm getting input from /etc/passwd, grepping to find users that are enabled login, cutting and getting the first segment before a colon, and sorting in alphabetical order -- then surrounding the resulting list of login IDs in option tags:
cat /etc/passwd | egrep "\[N?U" | cut -d : -f 1 | sort | sed -n 's/.*/<option value=\"&\">&<\/option>
Which yields:
<option value="loginID1"\>loginID1</option\>
,etc.
That's all fine, not a problem. But -- now I want to run each ID through 'lookup' and grep the name out, and then insert between the option tags, where the second ampersand is, like this:
<option value="loginID1">Firstname Lastname1</option>
Assuming that lookup loginID1 returns Firstname Lastname 1, how can I do this? It seems that I need to keep the original values of the /etc/password - parsed values while also running them through lookup. Is there any way I can do this in one line, without having to resort to loops/arrays in bash? Or will an in-line Perl script help?
Thanks!
posted by provolot to computers & internet (10 comments total)
for i in `egrep "\[N?U" /etc/password | cut -d: -f1 | sort`; do echo <option value=\"$i\">`lookup $i`; done
posted by mbrubeck at 1:20 PM on August 8, 2006