Question: So i am trying to complete this program that searches a medication list for user specified information. Search only the Medication Code field of the

So i am trying to complete this program that searches a medication list for user specified information.

Search only the Medication Code field of the data file displaying the all occurrences of matching Medication Code (s) and corresponding Generic Name or Dose.

E.g. A search for the Medication Code "6314", should not display any information about Medication Code "5341209". i.e. the search must be restricted to the information in the Medication Code field

Your program must not use any text processing utilities like awk, sed, or perl.

Medication list:

commA6314 ifosfamide 30 12 home5341209 urokinase 6314 37 educ 12345candesartin ug 200 3268 home32493320doxorubicin m^2 40-80 46 homeEH-1101 anti-ebo m^2 40-80 71 comm9230 garimycin pg 6000DNO 0 comm6807 haemogen-RL23units 40000 3 home86197820EH-1101 m^2 40-95 286 agri36B-987623-cisplantinL 250 108

this is the code i have so far i need it to only search the medication field instead of the entire line for $medcode

#!/bin/bash

# search medicine list and generate a report # script name: search.sh

# Loop to ask medication code and generic name or dose # Enter 'ZZZ' to quit while : do # taking medication code from the user echo -n "Enter Medication code? " read -r mcode # converting medication code to upper case for comparision if necessary mcode=$(echo "$mcode"|tr 'a-z' 'A-Z') # if mcode is ZZZ, quit from the outer while loop if [ "$mcode" == 'ZZZ' ] then break fi # loop to ensure generic name or dose is passed correctly # if generic name is 'G' or 'D' this loop terminates while : do # taking generic name or dose as input from user echo -n "See Generic Name (G/g) or Dose (D/d) ? " read gname # converting gname to upper for comparision in if condition below gname=$(echo "$gname"|tr 'a-z' 'A-Z') if [ "$gname" == 'G' ] || [ "$gname" == 'D' ] then break else echo "Please enter only G or D." fi done

# grepping given mcode in the medslist file and redirecting to file /tmp/result grep "$mcode" medslist>/tmp/result # traversing through /tmp/result file and print required category and medcode while read line do genname=$(echo "$line"|cut -c13-25) dose=$(echo "$line"|cut -c25-39) if [ "$gname" = 'G' ] then echo "$genname" elif [ "$gname" = 'D' ] then echo "$dose" fi done

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!