FInd the String between Two words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FInd the String between Two words
# 1  
Old 08-04-2008
FInd the String between Two words

Hi
I would like know how can write a script for find a string between two words.

My input like this:

a1 IN a1a1a1a1a1a1 OUT
b1 IN b1b1b1b1b1b1 OUT
c1 IN c1c1c1c1c1c1 OUT
.
.
.


now my out put like:

a1a1a1a1a1a1
b1b1b1b1b1b1
c1c1c1c1c1c1

please help on this.
# 2  
Old 08-04-2008
Hammer & Screwdriver There are many possible solutions, but here are three

Code:
> cat infile
a1 IN a1a1a1a1a1a1 OUT
b1 IN b1b1b1b1b1b1 OUT
c1 IN c1c1c1c1c1c1 OUT

> cat infile | awk '{print $3}'
a1a1a1a1a1a1
b1b1b1b1b1b1
c1c1c1c1c1c1

> cat infile | sed 's/IN /~/' | sed 's/ OUT/~/' | cut -d"~" -f2
a1a1a1a1a1a1
b1b1b1b1b1b1
c1c1c1c1c1c1

> cat infile | tr " " "\n" | grep [a-z][0-9][a-z]
a1a1a1a1a1a1
b1b1b1b1b1b1
c1c1c1c1c1c1

# 3  
Old 08-04-2008
Thanks yar.....
# 4  
Old 08-04-2008
With Perl:

Code:
perl -nle'print /IN (.*?) OUT/' input

# 5  
Old 08-04-2008
thanks for different solutions...
# 6  
Old 08-04-2008
Quote:
Originally Posted by koti_rama
My input like this:

a1 IN a1a1a1a1a1a1 OUT
b1 IN b1b1b1b1b1b1 OUT
c1 IN c1c1c1c1c1c1 OUT
.
.
.

now my out put like:

a1a1a1a1a1a1
b1b1b1b1b1b1
c1c1c1c1c1c1

please help on this.

Code:
cut -d ' ' -f3 FILENAME

(Note that cat is not needed for this or the other solutions posted.)
# 7  
Old 08-05-2008
Code:
awk '{print $3}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep only words containing specific string

Hello, I have two files. All urls are space seperated. source http://xx.yy.zz http://df.ss.sd.xz http://09.09.090.01 http://11.22.33 http://canada.xx.yy http://01.02.03.04 http://33.44.55 http://98.87.76.65 http://russia.xx.zz http://aa.tt.xx.zz http://1w.2e.3r.4t http://china.rr.tt ... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

3. Shell Programming and Scripting

Print ALL matching words in a string

Hi. str=" {aaID=z_701; time=2012-10-08 00:00:00.000}; {aaID=S_300; time=2012-10-08 00:00:00.000}]}; ansokningsunderlag={anmaln......} {aaID=x_500; time=2012-10-08 00:00:00.000}]}; ansokningsunderlag={anmaln......}" I want to print: z_701 S_300 x_500 if I use : echo $str | sed -n... (4 Replies)
Discussion started by: freddan25
4 Replies

4. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

5. UNIX for Dummies Questions & Answers

number of words in delimited string

Hi, I'm looking for one liner code for counting number of words in a delimited string.. I know about wc -w ..but if i give wc -w a.txt,b.txt it won't work with delimited sting as it was looking for files with a.txt and b.txt I know there will be a simple solution..i couldn't... (5 Replies)
Discussion started by: ammu
5 Replies

6. Shell Programming and Scripting

ksh cut out words from string

Hi, I have: export string1=qwerWhatever export string2=qwerWhatever1 export currdir=`pwd` echo $currdir gives back: /dir/dir/Whatever1 I want to take first 4 letters from string1 (in this case: qwer), compare it to string2 (in this case qwerWhatever1) and if string2 has in it... (8 Replies)
Discussion started by: chish
8 Replies

7. Shell Programming and Scripting

Assign words in a string to array

I have a string as "yes why not" I want to create one array variable with contents as one word per place in array.. for above string,the array variable should contain... x="yes,why,not" x = yes x = why x = not Please help me,I am stuck up in the problem since 2 days... (3 Replies)
Discussion started by: uday26
3 Replies

8. Shell Programming and Scripting

[sed] extract words from a string

Hi, One of the scripts creates logs in the format: progname_file1.log.20100312020657 where after file the number could be from 1 to 28 and after log. the date is attached in the format YYYYMMDDHHMISS progname_file<1-28>.log.YYYYMMDDHHMISS. Now I want to discard the .20100312020657... (7 Replies)
Discussion started by: dips_ag
7 Replies

9. Shell Programming and Scripting

Creating String from words in a file

Hi i have a file called search.txt Which contains text like Car Bus Cat Dog Now i have to create a string from the file which should look like Car,Bus,Cat,Dog ( appending , is essential part) String must be stored in some variable so i can pass it as argument to some other... (5 Replies)
Discussion started by: deepakthaman
5 Replies

10. Shell Programming and Scripting

splitting words from a string

Hi, I have a string like this in a file, I want to retrive the words separated by comma's in 3 variables. like How do i get that.plz advice (2 Replies)
Discussion started by: suresh_kb211
2 Replies
Login or Register to Ask a Question