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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Korn Shell Script 2

Status
Not open for further replies.
Apr 8, 2001
8
0
0
US
I have a script that needs to ask user where the data file is and what the data file name is and then ask what fields to show. There are only 3 fields, but I can't figure out how to allow it to put in multiple fields. I can get it to work where it asks for 1, but if I need it to know that 1,3 is field 1 and field 3, side by side. I'm stumped. Here's my code so far. I know there are more than one argument that can be passed in, but all my examples only have one and I'm stuck. This is how I try, but it will not work.

#!/usr/bin/ksh

echo "Enter the path to the data file: \n"
read pname

echo "Enter the file name of the data file: \n"
read flname

answer=y
while [ "$answer" = "y" ]
do

echo "Enter a field number that you wish to display: \n"
read fldnum
echo "Do you want to display another field? (y/n) \c"
read anymore
case $anymore in
y*|Y*) answer=y ;;
n*|N*) answer=n ;;
*) answer=y ;;
esac


cut -f$fldnum data.hw4
 
Why not simply asking once for a comma separated list of field numbers ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

I can change it to say, "Please enter fields you would like to see separtated by a comma Ex)1,2,3

Dont know how to put 1 and 3 to where I get columns 1 and 3 in my output.

sam
 
Actually, cut take fields in that form. cut -f1,3 will give you fields 1 and 3.
 
Something like this ?
#!/usr/bin/ksh
while [ ! -d "$pname" ]; do
echo "Enter the path to the data file:"
read pname
done
while [ ! -f $pname/$flname ]; do
echo "Enter the file name of the data file:"
read flname
done
while [ -z "$fldnum" ]; do
echo "Please enter fields you would like to see separtated by a comma Ex)1,2,3"
read fldnum
done
echo "$fldnum" | sed "s!,!$(echo \\t)!g"
cut -f$fldnum $pname/$flname

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top