Lets say I'm doing a database for fruits.Using a text file for it, inside contains, in this format,(Fruit:Quantity:Cost)Apple:10:1Orange:20:2Pears:10:3Banana:20:410 Apples at $1 each.20 Oranges at $2 each.10 Pears at $3 each.20 Bananas at $4 each.My simple script goes like this:echo Enter fruit to findread fruitecho Enter quantity to findread countecho Enter cost to findread costgrep $fruit FruitDB.txtIt will display the fruits in the database.But how do i use grep and cut together to find just by the quantity or the cost. In the quantity count area, let's say i enter 20, it will display the Oranges and Banana. Or when i enter count and cost, it will display just those that meet the conditions.
How to use grep and cut together?
grep;cut;database
You don't need cut at all, just bare grep is enough in the form:grep ^$fruit:$count:$cost$ FruitDB.txtRemove any variable you don't want to grep at the time (but leave separators :, and begining and end of line signs ^ and $ (for edge variables)).For example to grep those with count=20:$ grep :$count: FruitDB.txtOrange:20:2Banana:20:4grep those with count=20 and cost=2:$ grep :$count:$cost$ FruitDB.txtOrange:20:2