finding my location in a string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding my location in a string
# 1  
Old 03-08-2010
finding my location in a string

I'm a relative newbie and apologize if this is silly... Suppose I have a file with English words and their Spanish translations. I read them in like this:

Code:
while(getline < myfile > 0) {
     eng = $1
     SPAN[eng] = $2
}

Now, for every eng in SPAN, I want to scan through SPAN[eng] and search for a particular character, but it matters to me *where* in the spanish my character occurs.

Is there an easy way to track and check this?

Thanks for any pointers.

--Lee
# 2  
Old 03-08-2010
Assuming you mean awk code
Code:
myletter="c"
myposition=3
awk -v myletter=$myletter -v mypos=myposition ' {
     SPAN[$1]=$2
     if mypos == index(SPAN[$1], myletter) )
             {print $1, SPAN[$1], "has ", myletter, "at position", myposition}
     } ' inputfilename

# 3  
Old 03-08-2010
Thanks Jim. That does the trick.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Programming

Substitute string using location (preferably perl).

I have a string like. ATATATATTATTATATTATATTATT I want to substitute the characters to "C" by using these locations 3 7 10 18 15 20 desired Output: ATCCCCCTTACCCCCCCCCCTTATT any clue will be great help. :wall: thanks in advance. (2 Replies)
Discussion started by: admax
2 Replies

3. Shell Programming and Scripting

Finding a string with another string is found

finding a string with another string is found EX: abs c/- i want to find /-, then copy abs. i know it's easy use awk, but my problem is the substr syntax. substr($2,2,2) will give me /- but the conflict is /- is not always the second characted of the second string. (11 Replies)
Discussion started by: engr.jay
11 Replies

4. Shell Programming and Scripting

Put one string from one location to another location in a file

Hi Everyone, I have 1.txt here a b c' funny"yes"; d e The finally output is: here a b c d e' funny"yes"; (1 Reply)
Discussion started by: jimmy_y
1 Replies

5. Shell Programming and Scripting

How to append a string to a specific location in a line

Hi, I have a to modify a line and insert a keyword in the middle to a specific location. My line looks like this FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (ABC, DEF, GHI) I want to change it as FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING... (4 Replies)
Discussion started by: mwrg
4 Replies

6. Shell Programming and Scripting

Finding a word at specific location in a string

Hi All , I have different strings (SQL queries infact) of different lengths such as: 1. "SELECT XYZ FROM ABC WHERE ABC.DEF='123' " 2. "DELETE FROM ABC WHERE ABC.DEF='567'" 3. "SELECT * FROM ABC" I need to find out the word coming after the... (1 Reply)
Discussion started by: swapnil.nawale
1 Replies

7. UNIX for Advanced & Expert Users

Match the string and copy records to another location

Hi, I have particular set of files which have the below contents: ****** PBX TYPE:ID6 PBX-id: A11 rolled on 123456 368763 00 >>>>>> A11,2008-07-01 21:31:00.000,42,42112, ,XXXXXXXX A11,2008-07-01 21:40:00.000,6, , ,XXXXXXX A12,2008-07-01 21:53:00.000,68, , ,XXXXXXXX... (12 Replies)
Discussion started by: bsandeep_80
12 Replies

8. UNIX for Dummies Questions & Answers

Finding files in subdirectories from one location

Using ssh, is there a simple command to find files in subdirectories from, let's say, the home directory on a shared server? (2 Replies)
Discussion started by: endl
2 Replies

9. UNIX for Dummies Questions & Answers

How to get the location of word in a string

How to use instr function in awk ? to get the location a) for example instr('productiondata_12','data',1) to get the location of data using awk. b) for example instr('sampledata_rev_12','rev',1) to get the location of data and reaplce with "org" using awk. can anyone help ... (3 Replies)
Discussion started by: Vrgurav
3 Replies

10. Programming

finding stack location in C using program

Is there a way to find the address of stack memory writing a program? Please guide me (12 Replies)
Discussion started by: jacques83
12 Replies
Login or Register to Ask a Question