The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
using AWK how to extract text between two same strings santosh1234 Shell Programming and Scripting 2 12-23-2008 05:37 AM
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 12-03-2008 06:29 PM
Using awk to extract text Davizzle Shell Programming and Scripting 5 08-15-2008 01:09 AM
extract text b/w two delimiters dowsed4u8 UNIX for Advanced & Expert Users 6 01-18-2008 05:48 PM
How to extract text from xml file chrisf Shell Programming and Scripting 3 09-01-2007 02:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2009
Shell_Learner Shell_Learner is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 12
Extract particular text

I executed a following sed command
=> echo "a/b/c/d/e/f/g/h" | sed 's/\/[A-Za-z0-9]*$//g'
a/b/c/d/e/f/g

Now what if I want to extract "g" from "a/b/c/d/e/f/g/h" . That is second last string using SED.
  #2 (permalink)  
Old 04-24-2009
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...
Code:
basename $(dirname "a/b/c/d/e/f/g/h")
  #3 (permalink)  
Old 04-24-2009
Shell_Learner Shell_Learner is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 12
How will we do using SED?
  #4 (permalink)  
Old 04-24-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try this:

Code:
$ echo "a/b/c/d/e/f/g/h" | sed 's!.*/\(.*\)/.*!\1!'
g
$
  #5 (permalink)  
Old 04-24-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Hi Shell_Learner,

In awk it's bit simple as follows:

Code:
echo "a/b/c/d/e/f/g/h" |awk -F"/" '{ print $(NF-1) }'
might be needed for you in future
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 08:58 PM.


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