Example of my information:Fruit,Quantity:Cost,SoldRed Apple,10,1,5Green Apple,10,2,20Orange,20,1,10Here's my code:if      [ $fruit != $blank ] && [ $quantity == $blank ]; then        cut -d\, -f1 information.txt | grep $fruitelif    [ $quantity != $blank ] && [ $fruit == $blank ]; then        cut -d\, -f2 information.txt | grep $quantity My code will only display the intended search, so if you key in Apple, it will only display Red Apple and Green Apple but not the quantity, how do I make it to display all the information. Same as quantity, if you key in 20, it will only display 20.
How do I display the whole line of text?
shell script
Your cut is effectively removing the information you are looking for from the input you feed to grep. Use justgrep ^[^,]*$fruit[^,]* information.txtinstead ofcut -d\, -f1 information.txt | grep $fruitandgrep ^[^,]*,$quantity$ information.txtinstead ofcut -d\, -f2 information.txt | grep $quantityto filter the lines you are interested in. The regexp:^ starts the matching at the beginning of line;[^,]* matches any string not containing a comma (,);$fruit matches the string contained in the fruit environment variable;the other [^,]* should be obvious at this point.Once you add more fields into your data, you might need to modify the regexps - in that case any tutorial on those will come in handy, syntax is in the grep(1) man page (i.e. use: man grep).If you insist on using cut and your input is sorted, you can put the information back using join (for the first case):inf=information.txtcut -d, -f1 $inf | grep $fruit | sort -u | join -t, -j 1 - $infcut outputs the first field (-f1) of file whose name is contained in the environment variable inf, where fields are delimited with a comma (-d,);grep see above;sort sorts and removes duplicates (-u);join joins lines from its standard input (the - in next to the last argument) with the contents of the file given as the last argument. It uses a comma as a field separator (-t,) and joins lines whose first fields are identical (-j 1).The requirement to have sorted data comes from join (at least the one in the coreutils package) - I haven't checked how big problems you could run into with unsorted data.