Help with a script


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Help with a script
# 1  
Old 08-13-2013
Help with a script

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 Smilie

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
# 2  
Old 08-13-2013
Is this the sort of thing you are after? It runs in ksh, hence the odd comment at the top.
Code:
#!/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
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 08-13-2013
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! Smilie

I just want to be able to add to the bottom of the list a new username and matching name to accompany it Smilie

Thank you again for the first response as well as anything else you might be able to help with!
Robert
# 4  
Old 08-13-2013
Aha! I got it COMPLETELY the wrong way then Smilie
Let's try with this:-
Code:
#!/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? Smilie



Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 08-13-2013
You sir, are a scholar and a gentleman! I really appriciate that help, and it worked perfectly!
THANKS!

Robert
# 6  
Old 02-01-2014
Hope your instructor doesn't watch this forum :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question