The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 12-03-2008 06:29 PM
extract text b/w two delimiters dowsed4u8 UNIX for Advanced & Expert Users 6 01-18-2008 05:48 PM
To extract everything between two delimiters dowsed4u8 SUN Solaris 1 01-16-2008 02:49 PM
Extract values from log file wdympcf Shell Programming and Scripting 5 08-10-2007 04:52 AM
I need to extract last column of a file and compare the values vukkusila Shell Programming and Scripting 4 08-04-2007 12:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-16-2008
tsaravanan tsaravanan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 13
how to extract values b/w two delimiters

Hi,

Please help me to extrat values b/w two delimiters.

$ echo $abc
[%12345%]

i want to extract the value 12345 b/w %.
  #2 (permalink)  
Old 09-16-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,348
Some possibilities:


Code:
echo "$abc" | awk -F"%" '{print $2}'

or:


Code:
echo "$abc" | sed 's/\[%\(.*\)%\]/\1/'

  #3 (permalink)  
Old 09-16-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,560

Code:
var="[%12345%]"
IFS="%"
set -- $var
echo $2

  #4 (permalink)  
Old 09-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Or if the text is in a file,


Code:
sed -n 's/.*\[%\(.*\)%\].*/\1/p' file

You can echo "$string" | sed if the text is not coming from a file, of course.
  #5 (permalink)  
Old 09-16-2008
lramirev lramirev is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 8
You can use "tr" too.

Code:
echo "$abc" | tr -d "[%]"

  #6 (permalink)  
Old 09-16-2008
tsaravanan tsaravanan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 13
Hi all,

Thanks all. it working fine.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0