bash bash bash
August 8, 2006 1:03 PM Subscribe
Calling all bash/nix gurus.. please help me!
posted by provolot to Computers & Internet (9 answers total)
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>
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?