how to retrieve the word between 2 specific words with shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to retrieve the word between 2 specific words with shell script
# 1  
Old 02-17-2010
how to retrieve the word between 2 specific words with shell script

Hi,

I have a file content like:

Code:
:
:
<span class="ColorRed"> 1.23</span><br>
:
:

the value 1.23 will be changed from time to time, and I want to use a shell script command, e.g grep or sed, to retrieve only the value, how to do it?

Thanks!
Victor

Last edited by radoulov; 02-17-2010 at 04:03 AM.. Reason: Please use code tags!
# 2  
Old 02-17-2010
Try...
Code:
sed 's/[^0-9|.]//g' infile

# 3  
Old 02-17-2010
Hi,

Thanks a lot...

Can I have a further question, how to do that if the content looks like:

Code:
:
:
<span class="ColorRed"><img src="https://www.unix.com/../common/images/arrow_red_L.gif" width="26" height="26"> 1.23</span><br>
:
:


Victor

Last edited by radoulov; 02-17-2010 at 04:03 AM.. Reason: code tags
# 4  
Old 02-17-2010
It would be better if you showed more contents from your inputfile...
but check this now...
Code:
sed 's/.*\>\( [0-9|.]*\)\<.*/\1/g' infile

# 5  
Old 02-17-2010
generic, to remove '<>' tags
Code:
sed 's/<[^>]*>//g'

# 6  
Old 02-17-2010
Quote:
Originally Posted by frans
generic, to remove '<>' tags
Code:
sed 's/<[^>]*>//g'

I don't think that's the requirement...

Code:
sed 's/.*\>\( [0-9|.]*\)\<.*/\1/g' infile

# 7  
Old 02-17-2010
Hi,

Thank you all, it works!


Victor
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting: frequency of specific word in a string and statistics

Hello friends, I need a BIG help from UNIX collective intelligence: I have a CSV file like this: VALUE,TIMESTAMP,TEXT 1,Sun May 05 16:13:05 +0000 2013,"RT @gracecheree: Praying God sends me a really great man one day. Gotta trust in his timing. 0,Sun May 05 16:13:05 +0000 2013,@sendi__... (19 Replies)
Discussion started by: kraterions
19 Replies

2. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

3. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

4. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

5. Shell Programming and Scripting

How to retrieve a file from specific path using unix script?

Hi i'm new to shell script, i want to get the filename from specific location which i mentioned in my script. The scirpt should read the filename exactly using the following command "ls -ltr | tail -1". Could someone show me on this. Below is my script #!/bin/ksh PATH= /usr/ if then ... (4 Replies)
Discussion started by: fresher
4 Replies

6. 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

7. Shell Programming and Scripting

To search a file for a specific word in a file using shell script

Hi All, I have a sql output file has below. I want to get the values 200000040 and 1055.49 .Can anyone help me to write a shell script to get this. ACCOUNT_NO ------------------------------------------------------------ BILL_NO ... (8 Replies)
Discussion started by: girish.raos
8 Replies

8. Web Development

Retrieve all matches of occurences of words

Hi, I have rows like this. Retractor muscle (PRM) of Helix pomatia Genetic characterization of a prm- mutant Values of PRM data. Expression pattern of prmt5 in adult fish. PRMT-5 negatively regulates DNA genetic fusions of prM-E protein Methylation of Xilf3 by Xprmt1b... (1 Reply)
Discussion started by: vanitham
1 Replies

9. UNIX for Dummies Questions & Answers

How to count the occurences of a specific word in a file in bash shell

Hello, I want to count the occurences of a specific word in a .txt file in bash shell. Can somebody help me pleaze?? Thanks!!! (2 Replies)
Discussion started by: mskart
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question