The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
Cutting segment of a string msb65 Shell Programming and Scripting 5 11-04-2008 11:00 PM
CUT command - cutting characters from end of string JWilliams AIX 2 01-28-2008 09:12 AM
cutting part of string dhaval_khamar Shell Programming and Scripting 3 07-25-2005 11:18 AM
Cutting Up a String lesstjm Shell Programming and Scripting 4 09-21-2004 12:40 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 11-21-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Cutting a string based on the third occcurence of a character

Hello,
I am new to unix hence struggling with my requirement.
I have a string like :

ECR/CHQ/GBP/12345.out

I need to get only the ECR/CHQ/GBP portion of the string(cut the string based on the third occurrence of / )...How do it do it?

Many thanks
  #2 (permalink)  
Old 11-21-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
awk and sed examples:

Code:
echo "ECR/CHQ/GBP/12345.out"| sed 's!^\([^\/]*\/[^\/]*\/[^\/]*\)\/.*!\1!'
ECR/CHQ/GBP

echo "ECR/CHQ/GBP/12345.out"| awk -F/ 'BEGIN{OFS="/"} {print $1,$2,$3}'
ECR/CHQ/GBP
  #3 (permalink)  
Old 11-21-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Many thanks
  #4 (permalink)  
Old 11-21-2008
Konerak Konerak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
Or, even easier,

echo "ECR/CHQ/GBP/12345.out" | cut -d'/' -f1,2,3
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 12:48 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