Hello everyone! I am new here, and just started playing with Unix/Ubuntu and started learning scripting just this week. Sorry if the question is so basic
I have a file that has two columns, in column one I have usernames;
first.last
and in the second column I have the matching real name;
First Last
Some are longer names/usernames than others, so they are not lined up pretty (I did find help on the forum to do that, but my assignment wants it to be a simple space between the user.name and real name)
as an example:
first.last First Last
first1.last1 First1 Last1
firs.lastlast Firs Lastlast
is there a way to make a script that would allow me to prompt the runner of the script for a username for the first column, and a matching "real name" for the second, and have that be appended to the file?
I appriciate the help a great deal. Sorry if the post is a little wordy
~Robert
Is this the sort of thing you are after? It runs in ksh, hence the odd comment at the top.
#!/bin/ksh
read uid?"What users are you looking for? " # Prompt and accept input
grep "^$uid " file | read userid fn sn # Use your file name here
echo "The owner of $uid is $fn $sn" # Display result
Have I missed the point?
I hope that this helps,
Robin
Liverpool/Blackburn
UK
1 Like
Thanks for the fast response Robin!
I don't think I explained what I was needed all that well, so the response you gave wasn't able to help, but is appriciated all the same!
right now the file is called USERS.REF.BAK and it has a format similar to this
mark.wallace15 Mark Wallace
jimi.johns Jimmy Franks
sand.which Sand Which
Names have been changed to protect my classmates identities!
I just want to be able to add to the bottom of the list a new username and matching name to accompany it
Thank you again for the first response as well as anything else you might be able to help with!
Robert
Aha! I got it COMPLETELY the wrong way then :o
Let's try with this:-
#!/bin/ksh
read uid?"What users are you adding? " # Prompt and accept input
read wholename?"What is their human name? " # Prompt and accept input
echo "$uid $wholename" >> file # Display result
Is that a bit better? The >>
appends to the named file.
Have I done any better this time? There is no validation here, of course, so one could input anything, or even nothing. Is that a problem?
Robin
1 Like
You sir, are a scholar and a gentleman! I really appriciate that help, and it worked perfectly!
THANKS!
Robert
Hope your instructor doesn't watch this forum