Operating System - Tru64 Unix
1752656 Members
5416 Online
108788 Solutions
New Discussion юеВ

How to add a field with sed

 
SOLVED
Go to solution
Victor Semaska_3
Esteemed Contributor

How to add a field with sed

I have to admit that when it comes to understanding the bizarre syntax of regular expressions within sed it confuses the bejezus out of me.

Here's my problem. I have a colon(:) separated file which I have to add a field to the end of the 1st line. For example, the end of the 1st line might look like this:

...:u_minchg#86400:\

and I want it to look like this:

...:u_minchg#86400:u_nullpw@:\

I tried several things and the closest (I think) I got is:

sed "1s/:\$/u_nullpw@:\/"

but it doesn't work, the file remains unchanged. Help!

Thanks,
Vic

There are 10 kinds of people, one that understands binary and one that doesn't.
8 REPLIES 8
Ann Majeske
Honored Contributor

Re: How to add a field with sed

Check out "man edauth", the last example might help.

Ann
Victor Semaska_3
Esteemed Contributor

Re: How to add a field with sed

Ann,

I did try that but for some reason adding the u_nullpw@ field at the end doesn't work. It worked when I tried adding it to the end of the 1st line thus the question.

Problem with the 1st line is there nothing that's the same from account to account and I have to do this for all accounts. Besides, I'd like to figure how to do this stupid thing with sed. :-)

Thanks,
Vic
There are 10 kinds of people, one that understands binary and one that doesn't.
Ann Majeske
Honored Contributor

Re: How to add a field with sed

Hi Vic,

It shouldn't matter where in the entry the u_nullpw@ is, as long as it is before the chkent entry (chkent is used to indicate the end of the entry).

I'm wondering why you want to set u_nullpw@ in the individual accounts, though. It makes more sense to have it in the default file and put the entry u_nullpw just on the accounts that you want to be able to not have a password.

Ann
Victor Semaska_3
Esteemed Contributor

Re: How to add a field with sed

Hi Ann,

I'll try to make a long story short (hopefully :). Management wants to 'lock down' or in other words 'make more secure' all accounts on all our Alphas for better security. Some of these systems have been around for years and I ended up 'inhereting' them. Don't know what has been set and what hasn't been. So, I decided the safest thing to do is set all fields the way we want them to be.

From some testing that I did it seems that when you set a field to a value that's the same in the default local template, it won't be saved in the user's record. That field is removed from the user's record, or at least the fields that I tested on.

Vic
There are 10 kinds of people, one that understands binary and one that doesn't.
Ann Majeske
Honored Contributor

Re: How to add a field with sed

Vic,

It still makes more sense to me to update the default file with the fields that you want for all accounts, and then maybe scan all the accounts to make sure they don't have something different that overrides the default, but to each his own...

I played with edauth some (system is V5.1a PK6), and what I see is that if I use edauth interactively the field gets added to the user's extended profile entry and it doesn't matter whether it already exists in the default file or where I add it in the user's entry. If I use the edauth -g | sed | edauth -s sequence trying to append the field before the chkent field it does not get added to the user's entry whether or not it exists in the default file. If I try to add the field elsewhere in the user's entry it does get added to the user's entry. Sure looks broken to me.

Ann
Victor Semaska_3
Esteemed Contributor

Re: How to add a field with sed

Ann,

Thanks for your time on this matter. Since we're talking about 100's of accounts, we're going to do it en masse.

Still would like to know how the sed command should look like. Anybody know of a 'sed for Dummies' manual? :-)

Vic
There are 10 kinds of people, one that understands binary and one that doesn't.
Ann Majeske
Honored Contributor
Solution

Re: How to add a field with sed

I'm no genius with sed, but I just tried the following and it looks like it worked:
# edauth -g testme | sed '1s/\\/u_nullpw@:\\/' | edauth -s

The problem with this one is that it assumes that all accounts will be printed out as multiple lines with at least the first ending in \. From doing an edauth -g on my system, it looks like edauth -g prints out all accounts as at least 2 lines, but I don't think that behavior is guaranteed.

Ann
Hein van den Heuvel
Honored Contributor

Re: How to add a field with sed

I like the use of $ to anchor the search.

However:

- The sed command needs to be enclosed in single quotes.
- The backslash is an 'escape' character and needs to be escapsed itself by doubling up.
- If you include the colon in the match, then you'd better put it back
- The line number is not needed
- The rest is fine :-).

Here is the test I used. Seems to work for me:

edauth -g | head | sed 's/\\$/u_nullpw@:\\/'

Hein.