Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

case script - read input and redirect

Status
Not open for further replies.

westwood01

Technical User
Dec 28, 2003
41
US
Suppose I have a line numbered (error.dat) file that looks like:

1 : Jun 18 12:05:52 host: hostname1:/some/path/here/some.file
2 : Jun 18 12:05:52 host: hostname2:/some/path/here/some.file
3 : Jun 18 19:38:49 host: hostname3:/some/path/here/some.file

And I have an (error.ksh) script that looks something like:

#!/bin/ksh
echo "
1) View All Errors
2) Create File for Each Error
q) Quit"
echo ""
while true
do
read input
case $input in
1) clear
echo ""
echo "Listing All Errors:"
echo ""
awk '{print $0}' error.dat;./error.ksh;;
2) clear
echo ""
echo "Listing of Errors:"
echo ""
awk '{print $0}' error.dat
echo ""
echo "Select Line Number to Create File"
echo ""
LINE=`awk '{print $1}' data3.email`
read input1
if [ "$input1" = "$LINE" ]
then
echo "It worked"
else
echo "It failed"
fi
q) echo "Exiting..."
sleep 2
exit;;
*) echo "Please try again";./error.ksh
esac
done

Question:
If a user selects option2 and when prompted, enters the number 1 (or 2, or 3), how can I get that number entered to correspond to the same numbered line of the error.dat file? If I have left anything out pls let me know and I'll repost. thanks.
 
What about


select what in $(<error.dat);do
echo "You selected $what by typing $REPLY
done

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Neat - The select statement lists the parts of the file seperated by a space. How would I use select to list the entire line? thanks.
 
Put

IFS="
"

That's a newline after IFS=" as the first line of your script

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
The output is taking every string seperated by a space and making it an option to select.

19) 19:38:49
20) homer:
21) sbkeppdb1-ebu:/var/legato/rman/bin/ebuarch.PRTLPRDS
22) 4
23) :
24) Jun
25) 18
26) 19:38:49
27) homer:
28) sbkeppdb1-ebu:/var/legato/rman/bin/ebuarch.PRTLPROD
29) 45
30) :
31) Jun
32) 19
33) 01:19:50
34) homer:
35) sbknwsed2q2:/
36) 46
37) :
38) Jun
39) 19
40) 01:19:50
41) homer:
42) sbknwsed2q2:/var
43) 47
44) :
45) Jun
46) 19
47) 01:19:50
48) homer:
49) sbknwsed2q2:/edsys2
50) 48
 
Regarding the IFS, I added it to look like this:

IFS="
"
select what in $(<data3.email);do

I ran it, and while it ran, I am still getting the same output. Is the IFS in the wrong location?
 
I used this to get one line per selection:

IFS="$1,$2,$3,$4
"

Thank you mike.
 
I strongly suggest you read your shell's man page as the IFS you posted is unlikely that you wanted ...
 
Very perseptive of you PHV...

I was just posting back to say that the $'s are not needed afterall; mmy position of the second " was the fix I was looking for earlier.
 
Right, I hit enter too, but then spaced the " over to the right, must have thrown it off. Thanks again Mike.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top