Now I want to write to a file and I found that '>> Secure' works just fine, however what happens that when this automatic script is given a random file with a bunch of names and I get like names like this:
The script when finished will just give me 4 "BraBla"'s and when I give the password to them as well how can we tell whose user id is whose?
(btw the point of the script is to take a list of names, make a user id for each of em and make a random password for each of them and then write the full names, with the user id's and the paswords to a separate file.)
Firstly I'm figuring out how to append a number to the end of one of these said names, except the append sed command prints the character on the line after the userid and insert does it on the line before and I have no idea how to get it after the id. ANd I've been tearing through my Linux Shells by Example book and can find nothin.
Aside from the append command I'm putting idea's on paper on how to detect if a name already exists so far its like:
if [finds] $x, then >> Secure [/w] appended # (probly $x+i)
however when I try to test a form of this:
awk '/$x (#which should equal BraBla)/' Secure
it should've printed out all lines with BraBla to test to see if I can use command substitution in this, the command "works" as the "[cs326_2@Linux2.cs]" shows on the next line but displayed no output. *le sigh* what is wrong. Am I on the right track?
IP: Logged |
posted
How easy this is depends on a few things. State exactly how the problem is stated.
Btw, you may find it (far) easier to use awk for your purposes.
code:
awk '{split($0,names," "); fir = substr(names[1],1,3); las = substr(names[2],1,3); print $0, fir las}'
might give you some ideas.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
-The problem isn't state it runs but displays no output when I try to see if I could do a command substitute the entire cut function into the $x variable.
-When I try to append a number value it doesn't append it at the end of the name but instead appends it to the next line, I wish to know how to append/insert the character to the end of a name not on the line next or before.
IP: Logged |
posted
The problem was stated somehow; tell me how. What, specifically, did your teacher tell you to do?
One of the things it would be important to know is, does this script have to take into account existing usernames, or can it deal with just processing a list and ensuring all the usernames that result are unique?
As for adding a letter to the end of a line, stop thinking about it as inserting something in the file, think of it as reading everything in the file and outputting it again, with something at the end of the line(s) you want to modify. Use awk. Unix is based on a philosophy of piping text between commands, not modifying files in place.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
The assignment is to create a script that can take any list of names, make a unique userid based off of the first 3 chars of their first/last names (append a number if multiple) and from their createa random password based off of the Redhat Linux dictionary and write their full names, userid's and passowrd to a file.
IP: Logged |
posted
Another bit of useful info, what shell are you using? Incidentally, doesn't Hatrack have an anti-homework policy? Most forums do, I think.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
I'm asking for advice and what not, not for the actual code, unless of course I can't find said code in my Linux manual.
Perhaps consider how you might use an array of that sort to keep track of how many times a name is used, and what you might check in order to decide whether or not to append a number (and whether or not you might already have some handily unique number to append).
Think not of appending, but what all you want to write on a given line and how print works in awk.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
i c, ok I'll keep it in mind for when I get back to it.
IP: Logged |