Bash test if #- in string but NOT #-# or #-#-# -
i have 5 different references file , locations in it, in;
search | contents #- | some.htm#9-22 called pat= #-# | some.htm#1-some.htm#3 called pat2= #-#-# | some.htm#21-some.htm#-some.htm#4 called pat3= ; | some.htm#6-some.htm#13;some.htm#22-23 called pat4= else | some.htm#
there 550 of these references in csv data file.
the problem having figuring out how test variable contains reference see if contains search colum listed above. know contains special characters. have not found reference searching them in test online.
pat=[#-] if [[ $aliyah == $pat ]]; shir1="$(echo "$aliyah" |awk -f \# '{print $1}')" start1="$(echo "$aliyah" |awk -f \# '{print $2}'|awk -f - '{print $1}')" end1="$(echo "$aliyah" |awk -f - '{print $2}')" return
thanks
so made changes recommended below have no joy. test not matching , falling through default , not processing should. debug output
+ aliyah in '"${arr[@]:2:11}"' + pat='[#-]' + [[ some.htm#11-38 == \[\#\-\] ]] ++ echo some.htm#11-38 ++ awk -f '#' '{print $1}' + shir10=some.htm # fall through, should fill shir1
so after more searching tried
if [[ "$aliyah" =~ [#-] ]];
and stopped falling through
as feared testing positive patterns 2 , 3 also
put quotes around variable name:
if [[ "$aliyah" == "$pat" ]]; ...etc...
Comments
Post a Comment