Find position of specific word in a line
Hi
I have a line, aa bbb c dddd eeeee. How to read the position of the word "dddd", as "4" in bash. Please help. Thanks |
Code:
echo "aa bbb c dddd eeeee" | awk -v t="dddd" '{ for (x=1; x<=NF; x++) { if ($x==t) { print "x=" x; exit(0) }} exit(-1);}' |
Or a pure bash solution
Code:
#!/bin/bash |
Thanks
It worked... |
All times are GMT -5. The time now is 06:42 AM. |