Finding a word at specific location in a string

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a word at specific location in a string
# 1  
Old 09-14-2009
Finding a word at specific location in a string

Hi All ,

I have different strings (SQL queries infact) of different lengths such as:

       3. "SELECT  * FROM ABC"

I need to find out the word coming after the word "FROM" in a shell script. For this I am able to find the location of word "FROM". How can I find out the word at a location = location of word "FROM" + 1 ?
Is there any better alternative for achieving purpose other than finding out locations of words?


Last edited by vgersh99; 09-14-2009 at 10:49 AM.. Reason: code tags, PLEASE!
# 2  
Old 09-14-2009
sed 's/.*FROM \([^ ][^ ]*\).*/\1/' myFile

---------- Post updated at 08:49 AM ---------- Previous update was at 08:49 AM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

3. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be === (3 Replies)
Discussion started by: harpal singh
3 Replies

4. Shell Programming and Scripting

Using sed to replace a word at specific location

I'm try to change a the prohibit to aix for the lines starting with ssh and emagent and rest should be the same. Can anyone please suggest me how to do that using a shell script or sed passwd account required /usr/lib/security/pam_prohibit passwd session required ... (13 Replies)
Discussion started by: pjeedu2247
13 Replies

5. Shell Programming and Scripting

tail and redirect until finding a specific word

Hey guys, I'm a new bee to this forum as well as to Unix, just having a requirement which i'm not sure how to write shell script for it.. Here is my requirement This is related to tomcat catalina.out file. Just want to display the content of this file until it finds a word like 'server... (2 Replies)
Discussion started by: new_bee
2 Replies

6. Shell Programming and Scripting

Finding a specific word

Hi, I am trying to develop a script which should find a word if a particular word exists. Below is the content of the file. insert_job: test_job ----> job name days_of_week: all start_times: "16:00" date_conditions: 1 insert_job: test_job2 ----> job name days_of_week: all... (16 Replies)
Discussion started by: rpatty
16 Replies

7. Shell Programming and Scripting

Find and replace a string a specific value in specific location in AIX

Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . . (5 Replies)
Discussion started by: techmoris
5 Replies

8. UNIX for Dummies Questions & Answers

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: while(getline < myfile > 0) { eng = $1 SPAN = $2 } Now, for every eng in SPAN, I want to scan through SPAN and search for a... (2 Replies)
Discussion started by: DrLeeDetroit
2 Replies

9. Shell Programming and Scripting

how to Add word at specific location in line

eg . i have file x.txt contains : java coding , shell scriptting etc... now i want to add "is langauge" after word java. output should be java is langauge coding , shell scriptting etc... any idea how to use shell script to do it ? (10 Replies)
Discussion started by: crackthehit007
10 Replies

10. 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
Login or Register to Ask a Question