LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 02-22-2010, 01:50 AM   #1
lipun4u
Member
 
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Rep: Reputation: 15
string substitution


I was reading string substitution...


str=abcABC123ABCabc

echo ${str#a*C}
echo ${str##a*C}


Can somebody explain me how it works ??
 
Old 02-22-2010, 02:03 AM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Code:
str=abcABC123ABCabc
#   |----|          shortest
#   |----------|    longest
echo ${str#a*C} # 123ABCabc
# Strip out shortest match between 'a' and 'C'.

echo ${str##a*C} # abc
# Strip out longest match between 'a' and 'C'.

quote from abs guide'
 
Old 02-22-2010, 02:05 AM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Both of these are string deletions. The expression that follows the # is the pattern that is being matched (and deleted), in this case 'a*C'. In other words, the pattern is 'a', followed by 0 or more characters, followed by a 'C'.

The difference between the two examples is that the first does a minimal match (ie, finds the match from the start of the string that is the shortest), while the second does a maximal match (ie, finds the match from the start of the string that is the longest).

Last edited by neonsignal; 02-22-2010 at 02:07 AM.
 
1 members found this post helpful.
Old 02-22-2010, 02:19 AM   #4
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
reading this again I think I just quoted what your reading. So thanks to neonsignal its explained. strip out is the key word here. I hope you got it now'
 
  


Reply



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 with a sed substitution string hawgwild Programming 2 09-24-2009 02:35 PM
String Substitution Swapna173 Linux - Newbie 1 08-04-2008 06:22 AM
Substitution of a long string horacioemilio Programming 5 04-07-2008 09:21 PM
Complicated string substitution horacioemilio Programming 5 02-13-2008 06:40 PM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:31 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
Open Source Consulting | Domain Registration