06-19-2009
searching and mapping
Hi,
I just started looking into various aspect of unix shell scripting. I am completely new to the world of UNIX. Could any one help me in solving the following requirement.
I have a parameter file with some data e.g.
sample.param
-------------
Andrew=201
Bob=219
Shelly=239
Student_219=/dir1/stud.txt
Student_240=/dir1/stud2.txt
Now I need to write a shell script i.e. testStud.sh which will satisfy the following requirement:
1. I'll pass a string as an argument while running the script.
2. The script will search the string in sample.param file as a key and return the value for that key. if it's not present in the param file, it'll exit out of the program displaying appropriate message.
3.Now the value returned will be appended to the string "Student_" and the resultant string will be searched as akey in the param file and the value corresponding to this key will be returned.
To explain the requirement in a broader way... let's take an example. Let's say the user runs the script as ./testStud.sh Bob
Now value corresponding to the argument i.e. key "Bob" in param file is "219". Now "219" will be appended to "Student_" and the resulltant string is "Student_219". Now again this key will be searched in the param file and the final result will be the value "/dir1/stud.txt"
Again let's say some one runs the script as ./testStud.sh Roger
Now since there is no key named "Roger" in the param file, it'll exit out of the program with a message "key not found".
Could any one kindly provide me the shell script for testStud.sh?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
This is truly embarrassing but I have to know the answer anyway :p
Can anyone share, how to assign keyboard mapping in hp-ux system? Every time I issue command which contain character "@", it'll go the next line. What I need is how to assign the character "@" to @ as it is supposed to be.
... (2 Replies)
Discussion started by: Olli.Lang
2 Replies
2. Shell Programming and Scripting
Dear Friends,
Please help me on this
I have file A.txt containing text lines as below
grectec; 30 ,50, 60, base_123 ; top09
grectec; 30 ,55, 60, base_123 ; top09
grectec; 10 ,53, 60, base_123 ; top09
grectec; 50 ,57, 60, base_123 ; top09
...
...
another file B.txt containing test... (4 Replies)
Discussion started by: Danish Shakil
4 Replies
3. UNIX for Dummies Questions & Answers
Hi we have a situation where some printers are on a server that sometimes has to be rebooted. If this happens the Unix boxes we have that are referencing the printers in the vfstab file fail to work even when the print server is brought back up. Does anyone know if it would be possible to put... (0 Replies)
Discussion started by: Hadleyshope
0 Replies
4. Shell Programming and Scripting
I have the following arrays with different lengths that I want to map them with the same key.
# Week numbers, 8 columns
@headers = ("2011-34", "2011-35", "2011-36", "2011-37", "2011-38", "2011-39", "2011-40", "2011-41");
%data = ("2011-34", BCE,
"2011-35", YZA,
"2011-36",... (5 Replies)
Discussion started by: tqlam
5 Replies
5. Shell Programming and Scripting
without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies
6. Shell Programming and Scripting
Hello,
I do not know if this is the right title to use. I have a large dictionary database which has the following structure:
where a b c d e are in English and p q r s t are in a target language., the two separated by the delimiter =.
What I am looking for is a perl script which will take... (5 Replies)
Discussion started by: gimley
5 Replies
7. Red Hat
What is the eqiuvalent of /dev/dsk/rdsk in linux vs Solaris (1 Reply)
Discussion started by: walnutpony123
1 Replies
8. Homework & Coursework Questions
Please let me know if mounted on in Unix and Mapping in Windows are same thing??? (1 Reply)
Discussion started by: MZC
1 Replies
9. UNIX for Dummies Questions & Answers
please forgive me. i know this is unix forum.
CIFS can map to shared windows folder.
i just wonder if windows can map to unix shared folder.
if yes, please enlight me... (5 Replies)
Discussion started by: lawsongeek
5 Replies
10. Shell Programming and Scripting
INPUT
13333--TEXT1
14444--TEXT2
13333--TEXT3
12233--TEXT5
14444--TEXT5
12233--TEXT1
12222--TEXT5
13333--TEXT09
what I'm looking for is something using awk arrays with below given output.
14444--TEXT2,TEXT5
13333--TEXT1,TEXT3,TEXT09
12233--TEXT5,TEXT1
12222--TEXT5 (6 Replies)
Discussion started by: busyboy
6 Replies