Finding position of space in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding position of space in a variable
# 1  
Old 01-31-2012
Finding position of space in a variable

HI All,

am trying to find the position of space in a variable, it is working for other characters other than space
Code:
ulab="ulab1|ulab2"
find_pos=`expr index $ulab '|'`
echo $find_pos

above code worked fine but below one says syntax error
Code:
ulab="ulab ulab2"
find_pos=`expr index $ulab ' '`
echo $find_pos

can some one please help me....

Many thanks

Last edited by Franklin52; 02-01-2012 at 03:41 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-31-2012
try
Code:
expr index "$ulab" ' '

Without the quotes, $ulab splits into two strings on the commandline.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-31-2012
beauty....

Many thanks for the quick response.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python variable at different position

I have a file which records banking transactions say like below. user1 has deposited 10,000$ in his account user2 has deposited 11,000$ in his account user1 has withdraw today 5000$ from his account. Lets say i read this file and convert each line as a list. username= word action=... (1 Reply)
Discussion started by: sahil_shine
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies

3. Shell Programming and Scripting

Get character position within variable

Hi all let's say i have a file named 1234_v2_abcd i need to find the position of the character located after _v, in above case this would be character number 2 the count of the characters before _v can change, but i always have a number after _v can anybody help :) (4 Replies)
Discussion started by: gigagigosu
4 Replies

4. UNIX for Dummies Questions & Answers

Help with finding matching position on strings

I have a DNA file like below and I am able to write a short program which finds/not an input motif, but I dont understand how I can include in the code to report which position the motif was found. Example I want to find the first or all "GAT" motifs and want the program to report which position... (12 Replies)
Discussion started by: pawannoel
12 Replies

5. Shell Programming and Scripting

Finding the most positive and negative value and defining its position

Hi, I have a file that looks like this: Jake 2 3 4 6 4 3 -2 -1 Jerry 1 2 3 2 1 7 -6 -1 Timmy -1 -4 -5 -8 9 3 1 I want to find the most positive and negative value for each row and also define its position (based on column #) So the output would look... (7 Replies)
Discussion started by: gisele_l
7 Replies

6. Shell Programming and Scripting

Finding relative position in a file

Hi, I have a file like 123 aaaaaaaaa ddddddddd vvvvvvvvv 345 ssssssssssss dddddddddd fffffffffff dddd ff 567 --------- sssssssss ddddddd eeeeeeeee (4 Replies)
Discussion started by: saltysumi
4 Replies

7. Shell Programming and Scripting

Finding character mismatch position in two strings

Hello, I would like to find an efficient way to compare a pair of strings that differ at one position, and return the difference and position. For example: String1 123456789 String2 123454789 returning something - position 6, 6/4 Thanks in advance, Mike (5 Replies)
Discussion started by: etherite
5 Replies

8. Shell Programming and Scripting

Help in finding the max and min position

Hi, I have this input file called ttbitnres (which is catenated and sorted):- 8 0.4444 213 10 0.5555 342 11 0.5555 321 12 0.5555 231 13 0.4444 400 My code is at :- #!/bin/bash echo -e Version "\t" Number of Pass "\t" Number of Fail "\t" Rank Position "\t"Min "\t" Max... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

9. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

10. Shell Programming and Scripting

search in finding position of a string in avariable

Hi, I have to find a text in a variable and need to get the position of it. say, a="This is Example Example1 xxx yyy Example" if i search for "Example" then i should get the location of the starting location "Example". and in next iteration it should give the location of next "Example" ... (2 Replies)
Discussion started by: smr_rashmy
2 Replies
Login or Register to Ask a Question