I have a list containing strings. All strings should have either "smp" or "drw" else it is considered an error. I have written this code below. Any better ideas to tackle this?
set fdrw = 0
set fsmp = 0
foreach f ($Lst)
set fdrwtag = `echo $f | awk '/drw/'`
set fsmptag = `echo $f | awk '/smp/'`
if ($fdrwtag != "") set fdrw = 1 # Darwin tag detected.
if ($fsmptag != "") set fsmp = 1 # Simplex tag detected.
if (($fdrw == 0) && ($fsmp == 0)) then
echo "\nERROR: $f Does not contain 'drw' or 'smp'.\n"
exit 1
endif
if (($fdrw == 1) && ($fsmp == 1)) then
echo "\nERROR: $f Contains both 'smp' and 'drw'.\n"
exit 1
endif
end
I have tried
set AierrLst = `echo $AfullNameLst | awk 'BEGIN {ORS="";RS=" "} !/drw|smp/'`
set nf = `echo $AierrLst | awk '{print NF}'`
if ($nf > 0) then
foreach f ($AierrLst)
echo "ERROR: $f File name does not have 'smp' or 'drw' tag"
end
endif
but I am getting
/drw: Event not found.
---------- Post updated at 02:41 PM ---------- Previous update was at 02:24 PM ----------
Fixed it, seems if I have a space after ! it works
set AierrLst = `echo $AfullNameLst | awk 'BEGIN {ORS=" ";RS=" "} ! /drw|smp/'`