Hi I am new to programming.
While trying to execute the script below,
with an input file of this form (in this case they are called nohd*.txt
files)
NSGEAPKNFGLDVKITGESENDRDLGTAPGGTLNDIG
IIIIMMMMMOOOOOOOOOOOOOMMMMMMMMMMMIIII
I want to count the columns that have text from file d.txt
, see next.
D
O
to do this I wrote the following script
#!/bin/bash
for z in {1..141}
do
a=0
l=$(tail -1 nohd$z.txt | wc -m)
x=$(cat d.txt)
for ((p; p<=l; p++))
do
if [ "$(cut -c $p nohd$z.txt)" = "$x" ] ; then
a=$((a+1))
p=$((p+1))
fi
done
echo $a
done
I'm running this script using ./script
it shows this error:
cut: invalid byte/character position ‘{1..351}’
it turns correctly only the first value, for the rest of values it turns 0 the expected output is in the following form
5
20
4
Please, can anyone help me with this? Thank u
sh script.sh
?./script.sh
?bash script.sh
? Something else? Please edit your question and clarify. Also, please show your expected output as I requested before.p
should be1
for the first comparison withcut
, so try to change your loop tofor ((p=1; p<l; p++))
and you probably don't need to incrementp
withp=$((p+1))
(remove it).