LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-17-2008, 01:38 PM   #1
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
Another modification of a variable


name=/data/cur/00000.chd.hgt

now i need to remove /data/cur and want the vairable as
name=0000.chd.hgt

i tried cut but it didnt work for me. can anyone let me know how to do it?
thanks
 
Old 06-17-2008, 01:41 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
This is a task for the basename command:
Code:
name=$(basename $name)
See man basename for details. Or, without calling an external command:
Code:
name=${name##*/}
This strip the longest part of the pattern that matches the front of the string, where the pattern is any sequence of characters followed by slash "*/".

Last edited by colucix; 06-17-2008 at 01:45 PM.
 
Old 06-17-2008, 01:50 PM   #3
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks . it is working.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 06:21 PM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 10:29 AM
Variable modification in script angel115 Programming 3 01-05-2007 11:00 AM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 12:23 PM
How can I do some modification to my initialized "env" environment variable? yuzuohong Linux - General 3 12-18-2002 04:41 PM


All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration