Trim the sentence containing colon and period to extract a word in between


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trim the sentence containing colon and period to extract a word in between
# 1  
Old 11-28-2010
Trim the sentence containing colon and period to extract a word in between

Hello All ,
i am a newbie in korn shell scripting trying to trim a sentence that is parsed into a variable . The format of the sentence has three words that are separated from other by a
" : " colon and "." period . Format of the sentence looks like

sampleword:sampleword.sampleword

The result should contain the word that is in between the " : " and period "." in the sentence that should be sent to the variable.

Can anyone help me with scripting this scenario.

Thank you

Venu
# 2  
Old 11-28-2010
Code:
$ echo sampleword1:sampleword2.sampleword3 | awk -F[:.] '{print $2}'
sampleword2

# 3  
Old 11-28-2010
Code:
var2=${var1%.*}
echo "${var2#*:}"

# 4  
Old 11-28-2010
Code:
echo sampleword:sampleword.sampleword  |cut -d: -f2 |cut -d. -f1

# 5  
Old 11-28-2010
Code:
$ echo sampleword1:samplewor2.sampleword3 | awk 'NR==var' var=2 RS=[:.]
samplewor2

# 6  
Old 11-30-2010
thank you folks

My sincere thanks to all of you folks ......worked fantastic........
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract only relevant part from a sentence?

Hello All, I have a file with details such as below. How do i extract only the host and port ? eg: dbs.ads.com 1521 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbs.ads.com)(PORT=1521))(CONNECT_DATA=(SID=vug)))... (5 Replies)
Discussion started by: JohnJacobChacko
5 Replies

2. Shell Programming and Scripting

Print one sentence 40 to 50 words end with period in a file

Hi All, Is there another way to achieve this? how get short phrase in a sentence with character count of 100 to 155 words end with period but don't end something like 50,000. . Here's my current script but the output is not good. This will use for my snippets or preview. grep... (6 Replies)
Discussion started by: lxdorney
6 Replies

3. Shell Programming and Scripting

Remove First word of a sentence in shell

Hi there, How I remove the first word of a sentence. I have tried. echo '1.1;' ; echo "$one" | grep '1.1 ' | awk '{print substr($0,index($0," ")+1)}' For the below input. 1.1 Solaris 10 8/07 s10s_u4wos_12b SPARC Just want to know if there is any shorter alternative. (3 Replies)
Discussion started by: alvinoo
3 Replies

4. Shell Programming and Scripting

SED (or other) upper to lowercase, with first letter of first word in each sentence uppercase

The title pretty much defines the problem. I have text files that are all in caps. I would like to convert them to lowercase, but have the first letter of the first word in each sentence in uppercase. I already have SED on the server for fixing / tweaking text files, but I'm open to other... (5 Replies)
Discussion started by: dockline
5 Replies

5. Shell Programming and Scripting

Extract a word from sentence

$SET_PARAMS='-param Run_Type_Parm=Month -param Portfolio_Parm="997" -param From_Date_Parm="2011-08-09"' Want to extract the value of "Portfolio_Parm" from $SET_PARAMS i.e in the above case "997" & assigned to new variable. The existence order of "Portfolio"Parm" can change, but the name... (2 Replies)
Discussion started by: SujeethP
2 Replies

6. Shell Programming and Scripting

extract a field from a long sentence!

Hi, I want to extract the value of LENGTH column (high-lighted in red) from a file which will have several lines as shown below: <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME ="UNIX" NULLABLE... (4 Replies)
Discussion started by: dips_ag
4 Replies

7. Shell Programming and Scripting

extract from a long sentence

Hi, There's a long sentence from which I need to extract only the part which is at the right side of the word LENGTH i.e. 15 long sentence : <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME... (3 Replies)
Discussion started by: dips_ag
3 Replies

8. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

9. Shell Programming and Scripting

How do you split a sentence after every nth word

Hi, I think my problem is a "simple" one to resolve. What i am looking for is a way in sed/awk to split a long line/paragraph into say 5 words per line. For example: Sentence/paragraph contains: 102 103 104 105 106 107 109 110 .... I would like the output to be (if splitting every 5... (5 Replies)
Discussion started by: muay_tb
5 Replies

10. Shell Programming and Scripting

Truncate the word from a sentence

Hi, The first line of a file is as follows: example.4ge v.45352 Report for April 28 May 2010 I need to remove the word example.4ge v.45353 from that line. I used the following command to truncate it sed 's/example.4ge v.45352//g' $filename But here the version number 45352 may... (4 Replies)
Discussion started by: Kattoor
4 Replies
Login or Register to Ask a Question