LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-17-2007, 05:52 PM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

Rep: Reputation: 30
bash string manipulation


Hi,
how can i change "../dir" to "/dir"?

Thanks
 
Old 06-17-2007, 06:13 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 328Reputation: 328Reputation: 328Reputation: 328
You can use a substring function:

Code:
someVar=${someVar:2}
The above takes the substring of the variable ("someVar") starting at the third character (0-based).
 
Old 06-17-2007, 06:15 PM   #3
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
Here ya go:

Code:
echo "../dir" | sed -e 's/\.\.//g'
HTH,

Centinul
 
Old 06-17-2007, 07:45 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
bash comes with its own string substitution, there's no need to call external commands.
Code:
echo ${var//./}
 
  


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
string manipulation in BASH ovince Programming 4 04-16-2007 08:15 PM
String manipulation Manuel Alvarado Linux - Newbie 2 09-06-2006 10:49 PM
String manipulation with BASH script King V Programming 9 04-21-2006 04:15 PM
string manipulation mannahazarika Programming 6 12-31-2005 12:02 PM
bash + string manipulation dave bean Programming 7 02-16-2005 12:16 PM


All times are GMT -5. The time now is 04:23 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration