LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   String Substitution (https://www.linuxquestions.org/questions/linux-newbie-8/string-substitution-660309/)

Swapna173 08-04-2008 06:15 AM

String Substitution
 
HI Guys,

I get File Names in as I or U as Suffix at the End of a File Name and I wanted to retrieve that I or U from the File name and run the processes acordingly.

I got the solution to this as well.
For Ex:

a="US_SALES_08_2008_I"
b=`echo ${a##*_}`

the variable b displays I in this case. But i wanted to know the role that # and * plays in the command.

Can i get information on any site from whether i can learn the shortcuts and more information on the linux commands as well.

Thanks in advance,
Swapna

colucix 08-04-2008 06:22 AM

This is an example of parameter substitution. The syntax here is
Code:

${var##Pattern}
which means remove from $var the longest part of $Pattern that matches the front end of $var.
In a pattern the asterisk means any sequence of characters (zero included). In your example all the characters before the last underscore and the underscore itself are removed, leaving I or U as required.

You can find a detailed description of parameter substitution, along with a lot of examples, in the Advanced Bash Scripting Guide, here. A pdf version of this document is also available.


All times are GMT -5. The time now is 07:00 PM.