Results 1 to 2 of 2
Thread: New to scripting. HELP PLEASE!!!
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Mar 2011
- West Jefferson, NC
New to scripting. HELP PLEASE!!!
I have been playing with Linux/Unix for about a year now and recently in my 2nd semester of Network Engineering we have started basic scripting.
I am totally lost.
We have no book in our class, and the instructor will give us very simple (simple to you guys) examples of how to use the "sed" or "tr" commands and then he gives us an assignment to do and dismisses class.
Once I get the script started, I can stumble my way through it enough to make it work, but I am not really understanding what I should be doing and why.
For Example, this is my current homework assignment:
Review of tr command.
Create a script to create unix accounts from the /home/share/account.dat file. The accounts should be at most 8 characters long, using lower case letters, and created from the last name + the first initial. If the last name is 8 characters or longer it should be up to the 8 character of the last name. The password for the accounts should be created by using the employee status followed by the first and last initals and the last 4 digits of the social security number. No duplicate account may exist.
368613610 MOFFETT, IVY FT
Account moffetti has a password of fim3610.
Where do I even begin with this? Please help, I am so lost.
- Join Date
- Nov 2008
- Tokyo, Japan
The "sed" command uses the infamous and highly essoteric "regex". "Regex" is short for "Regular Expression", which is essentially a very simple language for doing find-replace operations on strings. "Sed" is short for "stream edit" because you can pipe a file to "sed" and sed will execute the search and replace command once for every line in the input file.
Do a quick google search for "Linux sed regex examples". That would be my starting point.
The "tr" (short for "translate") command can be used to convert input to all lower-case. Check the "tr" manual page. For good measure, you can pipe information to "sort -u" to make sure all entries are unique, but I would rather the system fail with an error message if it tries to create two users of the same name.
If you don't know what I mean by "pipe", you should ask for tutoring from your teacher. But to give you a hint, you can pipe files through "sed", and replace each input with a "useradd" command:Code:
sed -e 's/<regex-pattern-match>/useradd \1/' </home/share/account.dat | tr <switches> >output.file source output.file
Let us know how it goes.