A file is modified by a script using an input file-141,141_1,BAR,HONDA,ps2_0,unassigned,ps3_0,Unassigned,ps4_0,Unassigned,ps5_0,Unassigned,ps6_0,Unassigned,ps7_3,TILL WILL,.....Input file-141,ps7,TILL WILLNow I need to search whether to column ps7_3 is updated with the correct value.So from the input file, I separated the columns-while read -r line;dosub1=$(echo $line|cut -f 1 -d ',');sub2=$(echo $line|cut -f 2 -d ',');sub3=$(echo $line|cut -f 3 -d ',');sub4=$(echo $sub2'.*,'$sub3|sed -e s/\(.*\)\r/'\1'/);echo $sub1;echo $sub2;echo $sub3;echo $sub4;grep $sub4 modded_file.csv.dat;done<input.csvThe output being-141ps7TILL WILL'ps7.*,TILL WILL'grep: WILL': No such file or directoryBut when I run     grep 'ps7.*,TILL WILL' modded_file.csv.dat, it works. How can I grep a variable as shown above, in a file?
Grep a variable in a file
shell;grep;variable
As you can see from your input you have space symbol in variable sub4 so rewrite this line:grep $sub4 modded_file.csv.dat;to begrep $sub4 modded_file.csv.dat;(Additions by @philippos)And $sub4 should not contain the single quotes ', because they would be considered part of the search pattern.I think your misconception is the order of how quoting and expansion is performed: You think first variables will be expanded and then quoting is performed, so after expansion the single quotes of the variable would quote the string. But in fact quoting is done before variable expansion, so you need to quote the $sub