What I want is to grab the usernames after "uid=" and before the following comma. I cannot figure this out.
I then need to add a new line to each user's section. This new line is the same for all users, with the exception of needing the specific username for that user. For example I would like it to do this:
<--First User-->
<function>account='uid=user1,.......
<newlycreatedline>hello my name is user1......
<--Second User-->
<function>account='uid=user2,.......
<newlycreatedline>hello my name is user2......
Anyone know how to script this out, I need this done for too many users to do it by hand.
Is this what the data actually looks like? The usual problem with XML is "whoops, I forgot to mention the data's full of whitespace and not one record per line because it looked bad".
Where the white space in front counts. 3 spaces for most 6 spaces for the object. I need the username grabbed to be in the two spots on the newly created line.
$ cat infile
<--First User-->
<function>account='uid=user1,.......
<--Second User-->
<function>account='uid=user2,.......
$ sed -n '/uid=\([^,]*\)/ { p; s/^.*uid=\([^,]*\).*$/\1/; h; s/^.*$/<newlycreatedline>hello my name is /; G; s/\n//; p; n }; p' infile
<--First User-->
<function>account='uid=user1,.......
<newlycreatedline>hello my name is user1
<--Second User-->
<function>account='uid=user2,.......
<newlycreatedline>hello my name is user2
vgersh that works for my original example, thanks! Now I just need to adapt it to the actual data structure. If you are able to look at that in my previous reply, that would be awesome. Either way, big help!
---------- Post updated at 12:02 PM ---------- Previous update was at 11:52 AM ----------
I guess my main question now is, how do I print the username inside of single quotes. For instance, instead of: