This question already has an answer here:

I am trying to create a shell script, below is a part of which where i am trying to extract some value from a record in a file:

tgt_val=`cat $file_name | grep "$string_name" | cut -d"|" -f$column_no`

This work perfectly when the specified column has some numeric or string value however it fails when th column has value as " * "



This command would work correctly for column 1,2 & 4

However in case of column 3 it gives me output as all the files in present directory.

Someone please help over this.

marked as duplicate by Gilles shell-script Jan 13 '16 at 23:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


What is happening is that somehow the * is being interpreted by the shell. Make sure all extracted fields are always properly quoted.

Not the answer you're looking for? Browse other questions tagged or ask your own question.