LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 04: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, 05: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: 326Reputation: 326Reputation: 326Reputation: 326
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, 05: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, 06:45 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
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 07:15 PM
String manipulation Manuel Alvarado Linux - Newbie 2 09-06-2006 09:49 PM
String manipulation with BASH script King V Programming 9 04-21-2006 03:15 PM
string manipulation mannahazarika Programming 6 12-31-2005 11:02 AM
bash + string manipulation dave bean Programming 7 02-16-2005 11:16 AM


All times are GMT -5. The time now is 11:40 PM.

Main Menu
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