How to find character position in file?

how to find character positionin file?
i.e
string = "123X568"

i want to find the position of character "X".

Thanks

string="123X568"
echo $string |awk -v s=X '{print index($1,s)}'

I get the follwoing error:

awk: syntax error near line 1
awk: bailing out near line 1

---------- Post updated at 09:11 AM ---------- Previous update was at 09:11 AM ----------

I am using BASH

Use nawk or /usr/xpg4/bin/awk on Solaris.

Or try..

echo ${string%X*} | wc -c

One more..

 echo "$string" | awk '{sub(/X.*/,"");print length($0)+1}'
1 Like

Another one:

echo 123x567 | awk -Fx '{print length($1)+1}'
1 Like
echo "123X568" | awk 'NF+=0' FS= OFS='\n' | awk '/X/{print NR}'