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
extracting a number from a string ROOZ Shell Programming and Scripting 6 06-06-2008 03:14 PM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 04:17 AM
Extracting part of a string sam_78_nyc Shell Programming and Scripting 8 04-25-2007 08:37 PM
extracting from a string preetikate Shell Programming and Scripting 1 03-11-2004 08:08 AM
Extracting String from a list odogbolu98 Shell Programming and Scripting 4 06-01-2002 03:48 AM

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-30-2007
start_shell start_shell is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 1
extracting a string

Hi All,

I am writing a shell script for which I am stuck with an extraction part.

I arrived till extraction of a path of file. Lets take an example.

I now have a file which contains following one line:

2348/home/userid/mydir/any_num_dir/myfile.text

Now I want to extract only "/home/userid/mydir/any_num_dir/" part of the string. Note that initial number can be anything, any number if digits.

To simplify the problem statement, I want to extract from a line, only part which is between first "/" and last "/", test should be ignored.

I need this because I want to change directory to /home/userid/mydir/any_num_dir/

Please help.

Thanks!
  #2 (permalink)  
Old 09-30-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
man dirname
  #3 (permalink)  
Old 09-30-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,246

Code:
awk 'BEGIN { FS=OFS="/" } { $1=$NF=""; print}

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 05:59 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