check index of a string by finding a letter in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check index of a string by finding a letter in it
# 1  
Old 01-24-2012
check index of a string by finding a letter in it

i would like to search for a letter in a string and get its index position.
example:
Code:
name='john'

pos=$(expr index $name o)

the result will be equal to 2 (2nd position)

how do you make this thing not case sensitive?
example:
Code:
name='john'

pos=$(expr index $name O)

the capitalization is the issue.



Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 01-24-2012 at 06:34 AM.. Reason: code tags
# 2  
Old 01-24-2012
Please use code tags next time, thanks.

Code:
pos=$(expr index $name [oO])

This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

C++ homework, finding a letter from a file

Write a program which asks user to enter a string and that string saves in a .txt file. After the file has been saved your program must count how many time letter 'a' has been reapeated ? Use fstream, string, and cctype libraries to make your jobe easier. I wrote following code #include... (1 Reply)
Discussion started by: solaris_user
1 Replies

2. Shell Programming and Scripting

[Solved] check if chars is a capital letter and translate it

how can i check if read -n 1 LETTER; LETTER is a capital letter and after translate in minuscule. i have thought with: tr or no? (7 Replies)
Discussion started by: tafazzi87
7 Replies

3. Shell Programming and Scripting

change each letter of a string

Is there a way to change each letter of a string to the next one in the alphabet, so that a becomes b and f becomes g, and digits become one unit bigger - 4 becomes 5 and 9 becomes 0. I want to change strings like ben123 to cfo234. (5 Replies)
Discussion started by: locoroco
5 Replies

4. Shell Programming and Scripting

Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu. But i must control their input. These are criteria: Input must have 4 signs First two signs are always lower case letters Input shall not have some special signs just letters and numbers ... (1 Reply)
Discussion started by: waso
1 Replies

5. Shell Programming and Scripting

Finding index values

I have an array XOFFS of size N. I have VDISTMIN and VDISTMAX. I want to find the beginning and and index in XOFFS such that values are within Example Let XOFFS = (10 20 30 40 50) If VDISTMIN = -20 and VDISTMAX = 20 Then ISTR = 1 and IEND = 2 as XOFFS through XOFFS fall within the... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Shell Programming and Scripting

How to check index of a array element in shell script?

Example - Script to find the index of a month from array MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" set -A MON $MONTHS A="Sun May 23 09:34:30 GMT 2010" getMonth=`echo $A|cut -c5-7` ##getMonth=May Arrayindex_in_MONTHS_array= ???? # { 0,1,2,3,4 } - at fifth place ... (7 Replies)
Discussion started by: KuldeepSinghTCS
7 Replies

7. Shell Programming and Scripting

First Letter in a String to be capitalized

Is there a way to cnvert first letter alone in a string to upper case. For eg: diamond should be converted to Diamond. Thanks in Advance, Kinny (6 Replies)
Discussion started by: kinny
6 Replies

8. Shell Programming and Scripting

Finding a letter in a string

How to check whether a particular string contains dot or not? Here I can not use grep as the string is not in a file. I will get this string from user input Thanks, (2 Replies)
Discussion started by: balamv
2 Replies

9. Shell Programming and Scripting

get only two letter from any string

I want get middle two latter of any string. Input: var="070108" output: var1="01" please help. (2 Replies)
Discussion started by: rinku
2 Replies

10. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies
Login or Register to Ask a Question