[SOLVED] how to stop egrep Pattern in Bash Script from catching what it is not suppose to?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to stop egrep Pattern in Bash Script from catching what it is not suppose to?
I am going to try and make this as understandable as possiable,
I am using a script that goes through files looking at the directory name when it finds one with the pattern it then acts on it within a 'if statment' the pattern is either in caps or lower case or mixed caps and lower case. Only two letters and number CD x. when I run this on the command line it works perfecly. but in the script it will grab a name that is does not even have any of the chars in the pattern then use it as if it does off of the 'if statment'. Now I will show you the code.
what this code does is off of a loop getting the path/fileName.ext then splits it up. looking for the ext to match 'mp3' if it matches then it looks to see what the name of that directory is that contains the mp3. If the name is CD x of any type Cdx cDx cdx , the x being a number. Then it will pull back one more directory to get the name of that directory to use instead for a metadata tag in the Album Tag, and not the CDx. It is written so that it does not matter how deep the tree goes it steps back one more directory no matter what to get the name of that directory, instead of the directory that is named CDx (CD 1 - CD 2 etc.)
Code:
find /path -type f -name "*.*" | while [ x -lt y ] ;
do read FILENAME;
.....
if [[ "$ext" == 'mp3' ]] ; then
AlbumDir=${path##*/}
string="$( echo "$AlbumDir" | egrep -o [C-c][D-d][0-9])"
echo "[[ "$AlbumDir" == *"$string" ]]"
if [[ "$AlbumDir" == *"$string" ]] ; then
nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
# returns dir one step back from the mp3 file
else
# returns dir with the mp3 in it
echo "NO CD DIR : $AlbumDir"
fi
fi
......
done
the results everything is echo'ed we see the complete path. In this examle we can see that it did what it is suppose to, nine directories down is the CDx directory then one back, being the two steps is the name of the directory to be used,
Code:
#<-- back forward -->
/media/data/dynamic-dir/baceAlbumName/New/New1/New2/New3/New4/New5/New6/New7/New8/New9/CD 2/2 Eden.mp3
xpath : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/New3/New4/New5/New6/New7/New8/New9/CD 2
xbase : 2 Eden.mp3
xfext : mp3
xpref : 2 Eden
path : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/New3/New4/New5/New6/New7/New8/New9/CD 2
pref : 2 Eden
ext : mp3
4444444444444444444444444444
[[ CD 2 == * ]]
foundCD : CD 2
AlbumDir : New9
RRRRRRRRRRRRRRRRRRRRRRR
where this file lays within the directory named "New" it still catches it as saying CDx, having typed this all out step by step to mimic the complete code on the command line it returns empty here within the script it grabs the name "New" as being CDx
string2="$( echo "$AlbumDir" | egrep -o '( CD | cd | Cd )' )"
## that will pick up CD 20 , CD 100, Cd 2 etc... but even with that and trying this on the IF statment
[ "$string" == *"$subString"* ]
[ "$string" == *"$subString" ]
[ "$string" == "$subString"* ]
[ "$string" == "$subString" ]
Sorry I didn't put up the resultes from what you wrote I just shared a different way I tired it after I tried yours
from what you wrote
Code:
echo "4444444444444444444444444444"
if [[ "$ext" == 'mp3' ]] ; then
AlbumDir=${path##*/}
string2="$( echo "$AlbumDir" | egrep -o [Cc][Dd][0-9] )"
echo
echo "string2 $string2"
echo
string="CD"
echo "[[ "$AlbumDir" == "$string2" ]]"
if [[ "$AlbumDir" == "$string2" ]] ; then
nPath=${path/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
else
echo "NO CD DIR : $AlbumDir"
fi
fi
echo "RRRRRRRRRRRRRRRRRRRRRRR"
with CD
Code:
/media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3/I Wanna Be Your Man **Bonus Track** - L. A. Guns.mp3
xpath : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3
xbase : I Wanna Be Your Man **Bonus Track** - L. A. Guns.mp3
xfext : mp3
xpref : I Wanna Be Your Man **Bonus Track** - L. A. Guns
path : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3
pref : I Wanna Be Your Man **Bonus Track** - L. A. Guns
ext : mp3
4444444444444444444444444444
string2
[[ CD 3 == ]]
NO CD DIR : CD 3
RRRRRRRRRRRRRRRRRRRRRRR
without CD
Code:
/media/data/dynamic-dir/baceAlbumName/New/3 Desire.mp3
xpath : /media/data/dynamic-dir/baceAlbumName/New
xbase : 3 Desire.mp3
xfext : mp3
xpref : 3 Desire
path : /media/data/dynamic-dir/baceAlbumName/New
pref : 3 Desire
ext : mp3
4444444444444444444444444444
string2
[[ New == ]]
NO CD DIR : New
RRRRRRRRRRRRRRRRRRRRRRR
on the egrep side of things it returns empty and seems to work now, If I modify it further like this - by stripping of the ${VAR[0-9]*]} -- then add the star * to the left side of the condtional statment this is what I get, But I think now it is a empty space that is causing it to not match when it has a 'CD' . 'Cd' within the dir name, because it is really
Code:
[[ 'CD ' == 'CD' ]]
which returns a false - not true .
its still not perfectly working -- it's late ,, I'll peck at it more tomorrow
Code:
echo "4444444444444444444444444444"
if [[ "$ext" == 'mp3' ]] ; then
AlbumDir=${path##*/}
string2="$(echo -e "$AlbumDir" | egrep -o [Cc][Dd])"
echo
echo "string2 "$string2""
echo
string="CD"
echo "[[ "${AlbumDir[0-9]*}" == "$string2" ]]"
echo "--> ${AlbumDir[0-9]*}"
echo
if [[ "${AlbumDir%[0-9]*}" == "$string2" ]] ; then
nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
else
echo "NO CD DIR : $AlbumDir"
fi
fi
echo "RRRRRRRRRRRRRRRRRRRRRRR"
Code:
/media/data/dynamic-dir/baceAlbumName/New/3 Desire.mp3
xpath : /media/data/dynamic-dir/baceAlbumName/New
xbase : 3 Desire.mp3
xfext : mp3
xpref : 3 Desire
path : /media/data/dynamic-dir/baceAlbumName/New
pref : 3 Desire
ext : mp3
4444444444444444444444444444
string2
[[ New == ]]
--> New
NO CD DIR : New
RRRRRRRRRRRRRRRRRRRRRRR
pref : 3 Desire
track Number : 3
fCount : 38
aCount 40
/media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3/I Wanna Be Your Man **Bonus Track** - L. A. Guns.mp3
xpath : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3
xbase : I Wanna Be Your Man **Bonus Track** - L. A. Guns.mp3
xfext : mp3
xpref : I Wanna Be Your Man **Bonus Track** - L. A. Guns
path : /media/data/dynamic-dir/baceAlbumName/New/New1/New2/CD 3
pref : I Wanna Be Your Man **Bonus Track** - L. A. Guns
ext : mp3
4444444444444444444444444444
string2 CD
[[ CD == CD ]]
--> CD
NO CD DIR : CD 3
RRRRRRRRRRRRRRRRRRRRRRR
OK I Tinkered with it somemore before tomorrow
this is what I got and it is a lot more now
their has to be a shorter way to do this, not having to use so much code to strip the white spaces off, or catch the pattern, it getting to look too complecated now
(I'm just starting with this stuff btw, string malnipulation and BASH )
Code:
echo "4444444444444444444444444444"
if [[ "$ext" == 'mp3' ]] ; then
AlbumDir=${path##*/}
string2="$(echo -e "$AlbumDir" | egrep -o [Cc][Dd])"
echo
echo "string2 "$string2""
echo
string="CD"
echo
AlbumDir="$(echo -e "${AlbumDir%[0-9][0-9][0-9]}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "1 - [[ "${AlbumDir}" == "$string2" ]]"
AlbumDir="$(echo -e "${AlbumDir%[0-9][0-9]}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "2 - [[ "${AlbumDir}" == "$string2" ]]"
AlbumDir="$(echo -e "${AlbumDir%[0-9]}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "3 - [[ "${AlbumDir}" == "$string2" ]]"
echo
echo "--> ${AlbumDir}"
echo "4 - [[ "${AlbumDir}" == "$string2" ]]"
if [[ "${AlbumDir}" == "$string2" ]] ; then
nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
else
echo "NO CD DIR : $AlbumDir"
fi
fi
echo "RRRRRRRRRRRRRRRRRRRRRRR"
this is a lot for each instance of a patteren of numbers -- this removes the spaces on the sides of what ever it is pipped to it - I strip off the numbers within it before pipping it to sed
results: this catches CD 1 Cd1 Cd 20 CD 12 CD 101 etc
Code:
/media/data/dynamic-dir/Cd 101/Over The Wall - Echo & The Bunnymen.mp3
xpath : /media/data/dynamic-dir/Cd 101
xbase : Over The Wall - Echo & The Bunnymen.mp3
xfext : mp3
xpref : Over The Wall - Echo & The Bunnymen
path : /media/data/dynamic-dir/Cd 101
pref : Over The Wall - Echo & The Bunnymen
ext : mp3
4444444444444444444444444444
string2 Cd
1 - [[ Cd == Cd ]]
2 - [[ Cd == Cd ]]
3 - [[ Cd == Cd ]]
--> Cd
4 - [[ Cd == Cd ]]
foundCD : Cd
AlbumDir : dynamic-dir
RRRRRRRRRRRRRRRRRRRRRRR
OK, My Brain just kicked in a little bit -- coffee burn out maybe getting to me
this is what I got it down to - I just caught it use two %% to get the farthest to the left of patteren [0-9] being one number - then strip the rest of it off along with it.
Here we see the directory name we are looking at in red, but it does not match your grep at all:
Code:
egrep -o [C-c][D-d][0-9]
Whilst I agree that the use of ranges is wrong here, the intent is to match, cdn, Cdn, CDn, cDn. The problem is that your directory has a space in it so none of these will ever match.
Yet you advise this was a successful run??
Now as far as I can see, none of your future versions change this so I am at a loss at the reason for using grep at all here??
Personally I would also not bother with grep at all and just use bash's pattern matching.
Another line that doesn't make any sense to me is:
Code:
AlbumDir=${path##*/}
Now maybe you did something to path prior to where I am seeing it, but if it is the path returned by find, this variable would now store the name of the mp3
Sorry for the confusion, but if you could provide more detail I may be able to help?
I have come into this a bit late, but I have to say I am more than a little lost
Now I am not sure if the complete script does more to other file types, ie. other than mp3, but if not, why does the find not just find mp3's?
Code:
find /path -type f -name "*.*"
find /path -type f -iname "*.mp3"
It seemed redundant to have that - either way with the
Code:
if [[ "$ext" == 'mp3' ]]
it does not matter one way or the other it will still catch the mp3's files having
Code:
find -type f -name "*.mp3"
just cuts back on search time. though I did have it like this
Code:
find -type f -name "*.mp3"
repeating the if statment catches it, in my real world script that I will use this in I will be using the
Code:
*.*
to work with other files within the dir structor too at the same time within a different loop within the whole script loop. jpg. png, txt etc ...
Quote:
Originally Posted by grail
You will notice I also included the use of 'iname' as it seems you cannot be sure of case
The next part that confuses me is where you say you have a successful run. Just looking at the path returned:
Here we see the directory name we are looking at in red, but it does not match your grep at all:
Code:
egrep -o [C-c][D-d][0-9]
Whilst I agree that the use of ranges is wrong here, the intent is to match, cdn, Cdn, CDn, cDn. The problem is that your directory has a space in it so none of these will ever match.
Yet you advise this was a successful run??
The spaces I did make mention of later on within all of that way "too much to read" that I posted in here.
Quote:
on the egrep side of things it returns empty and seems to work now, If I modify it further like this - by stripping of the ${VAR[0-9]*]} -- then add the star * to the left side of the condtional statment this is what I get, But I think now it is a empty space that is causing it to not match when it has a 'CD' . 'Cd' within the dir name, because it is really
Code:
[[ 'CD ' == 'CD' ]]
Quote:
Originally Posted by grail
Now as far as I can see, none of your future versions change this so I am at a loss at the reason for using grep at all here??
Personally I would also not bother with grep at all and just use bash's pattern matching.
cuz I am still learning what "items" are within Linux to use when working with strings, as i am seen many different ways that people show to get the same results using sed, grep, egrep awk etc.
Quote:
Originally Posted by grail
Another line that doesn't make any sense to me is:
Code:
AlbumDir=${path##*/}
Now maybe you did something to path prior to where I am seeing it, but if it is the path returned by find, this variable would now store the name of the mp3
Yes that is what the ..... are for to indecate other code prior to and after that sniplet I posted.
gives the complete path to the file, minus the file name, I just use that to strip off the furthest / from the left leaving the directory name to look at to see if it says any combination of CD possiable to computer aided human choice (hopefully). By using this
Code:
${path##*/}
Quote:
Originally Posted by grail
Sorry for the confusion, but if you could provide more detail I may be able to help?
now that I have responded to everything you wrote to me about, I left off at dealing with the spaces within a directory name, that you made mention of by using this code: if you get confused by what I have written just GOTO line 10 (MODED) make that LINE 11
Code:
.................
echo "4444444444444444444444444444"
if [[ "$ext" == 'mp3' ]] ; then
AlbumDir=${path##*/}
string2="$(echo -e "$AlbumDir" | egrep -o [Cc][Dd])"
echo
echo "string2 "$string2""
echo
string="CD"
AlbumDir="$(echo -e "${AlbumDir%%[0-9]*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "1 - [[ "${AlbumDir}" == "$string2" ]]"
echo
echo "--> ${AlbumDir}"
echo "2 - [[ "${AlbumDir}" == "$string2" ]]"
echo
if [[ "${AlbumDir}" == "$string2" ]] ; then
nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
else
echo "NO CD DIR : $AlbumDir"
fi
fi
echo "RRRRRRRRRRRRRRRRRRRRRRR"
.............
LINE 10 1/2
Let me brake it down for you (and others). I first check for mp3 for good mesure,
Code:
if [[ "$ext" == 'mp3' ]] ; then
then check to see if the directory name has the CD pattern within it by using egrep so that no matter how it is written as long as the CD part is not seperated by looking just for the pattern of CD with no spaces between the letters, and by leaving off any numbers that maybe there. I then use this code, modified per you pointing out to me (thank you very much ) that it is better to remove the ' - ' then have it in there
that insures (hopefully) that the search pattern will always be one form of CD or the other first. Then I take the name of the directory again then by removing any numbers off of the dir that maybe there as well by doing this
Code:
AlbumDir="$(echo -e "${AlbumDir%%[0-9]*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
the
Code:
AlbumDir="$(echo -e "${AlbumDir%%[0-9]*}"
takes the furtest to the left from the right side that is a number then removes the number along with everything else to the right of it. Now that all of the numbers are striped off it. I then pipes it to sed that removes any white spaces that maybe on either side
Code:
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
I do both side for the just in case, and to just be safe senerio. The whole thing put together giving me the results below.
Results:
Code:
/home/userx/JunkMusic1/Cd 101/The Puppet - Echo & The Bunnymen.mp3
xpath : /home/userx/JunkMusic1/Cd 101
xbase : The Puppet - Echo & The Bunnymen.mp3
xfext : mp3
xpref : The Puppet - Echo & The Bunnymen
path : /home/userx/JunkMusic1/Cd 101
pref : The Puppet - Echo & The Bunnymen
ext : mp3
4444444444444444444444444444
path : /home/userx/JunkMusic1/Cd 101
path##*/ Cd 101
string2 Cd
AlbumDir after striping number, and removing spaces
Cd
1 - [[ Cd == Cd ]]
--> Cd
2 - [[ Cd == Cd ]]
foundCD : Cd
AlbumDir : JunkMusic1
RRRRRRRRRRRRRRRRRRRRRRR
LINE 10
using egrep to get the search string with whatever form of CD is used in the directory name
then with AlbumDir again I now remove the number(s) off of it too, and spaces on either side of it,
Code:
AlbumDir="$(echo -e "${AlbumDir%%[0-9]*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
giving me this
Code:
Cd
then it checks it within the if statment
Code:
1 - [[ Cd == Cd ]]
--> Cd
foundCD : Cd
the path is this: /home/userx/JunkMusic1/Cd 101
then using this code to Change the name of the AlbumDir to one more dir back off of 'CD x' dir name I do this,
one directory back off from the directory that has the pattern I am looking for. It seems to work with any pattern of likeness of, CD xxx cd xxx cdxxx CDxxxxxxxx etc...
So, now it looks like I have a working chunck of code.
if you think you have a much better way in doing this please share it with me.
thanks !
LINE 11
--------- FurtherMore -- Now that I have wasted your time and mine, by writting all of what you just read and posting it, I then tested it again using my complete $HOME dir searching it enterly -- I got back a few false readings -- therefore it is not a working solution ..
fCount is amount of files looked at
aCount is amount of files to look at
Code:
working_dir="$HOME"
aCount="$(find "$working_dir" -type f -name "*.mp3" | wc -l)"
find "$working_dir" -type f -name "*.mp3" | while [ $fCount -lt $aCount ] ;
do read FILENAME;
for some reason it thought this and ones like this have the CD pattern within the dir. it looks like it matched on "blanks" in both $var's. Either more code is neeeded as in NULLing the vars then chekcing for NULL too, or spaces in the $vars then bypassing them, or a better way to insure the it does not pick up spaces off of the
AlbumDir="$(echo -e "${AlbumDir%%[0-9]*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
------------------- late night update ---
grep a CD pattern the run it through a case statment ---
Code:
string2="$(echo -e "$AlbumDir" | grep -o [Cc][Dd])"
#removes leading white space on both ends of string
string2="$(echo -e "${string2}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
Code:
string2="$(echo -e "$AlbumDir" | grep -o [Cc][Dd])"
#removes leading white space on both ends of string
string2="$(echo -e "${string2}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo;echo;echo;echo
echo "going into Case Statment"
echo
case $string2 in
"CD" ) nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
sleep 3
;;
"cd" ) nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
sleep 3
;;
"Cd" ) nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
sleep 3
;;
"Disk" ) nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
sleep 3
;;
"disk" ) nPath=${path%/*}
echo "foundCD : $AlbumDir"
NGetDirN=${nPath##*/}
AlbumDir="$NGetDirN"
echo "AlbumDir : $AlbumDir"
sleep 3
;;
* ) echo "NO CD DIR : $AlbumDir"
esac
you did forget to put the marker thingy % in this one though, and
Code:
path=${start_path/*}
should be like this
Code:
start_path=${FILENAME%/*}
though the logic is right , the path var has already stripped out the file with the ext on it. therefore the next bit of code did not work as a result of it. No Big Deal, really. I just removed that part of it. Had you started with the FILENAME then stripped the ext off of that instead, like this
Code:
while [ x -lt y ] ;
do read FILENAME;
path=${FILENAME%/*}
file=${FILENAME##*/}
ext=${file##*.}
# the ext is stripped to the farest right side starting off the left side just incase there is another . period within the file name.
# insuring you get the right period just before the ext.
done
with the code I am using to do that, strip it down giving path, filename, ext, I found it on the internet why they make it so long I do not know, I just keep copy pasting it,
no biggie. When I removed your path code keeping the rest I then got some output, but yeah! it's catching them now from what I see, because it flys by on the Term really fast, so I put a sleep in it when it finds a CD / disk dir. Thanks 4 ur Help!
I've got that
Code:
var=$[var//_/ } # var//search pattern/replace/} and var${var#*pattern}
down pretty good now. But what is this doing that you did with this part of the code?
Code:
"${CD_Dir,,}"
the two ,, within the brackets. what does that do for it?
Yes the first % sign is always eaten for some reason ... I forgot to check.
Quote:
though the logic is right , the path var has already stripped out the file with the ext on it. therefore the next bit of code did not work as a result of it. No Big Deal, really. I just removed that part of it. Had you started with the FILENAME then stripped the ext off of that instead, like this
As I do not have any files with that name, my 'start_path' variable was equivalent to a found file hence 'FILENAME', would be the same as 'start_path'
Quote:
# the ext is stripped to the farest right side starting off the left side just incase there is another . period within the file name.
# insuring you get the right period just before the ext.
The above is incorrect as ## is greedy and will overlook all periods until it finds the last one, hence it will find the one prior to the extension
,, sets all in the variable to lower case
^^ is partner to change all to upper case
Yes the first sign is always eaten for some reason ... I forgot to check.
Not arguing -- it is nothing to arguee about there -- it's kew
Quote:
Originally Posted by grail
As I do not have any files with that name,
what ???? you got no mp3's ...
Quote:
Originally Posted by grail
The above is incorrect as ## is greedy and will overlook all periods until it finds the last one, hence it will find the one prior to the extension
no, how so? it looks to the furthest . therefore it will only catch that last period, which will be the one just before the ext - try it, put 1 or more periods within a file then try it out.
results: as you see the one # only gets the very first . period whereas you have to use two ## to get to the right end of the file name using this methiod .. it is not being greedy.
The above is incorrect as ## is greedy and will overlook all periods until it finds the last one, hence it will find the one prior to the extension
NO because that is what we are looking for, the extention. It chops that period off and everything to the left of it, leaving just the extention. as you just seen in my actual data output showing you
Code:
# - goes left to right shortest
## - goes left to right to the furthest
% - goes right to left shortest
%% - goes right to left to the furthest
Quote:
Originally Posted by grail
,, sets all in the variable to lower case
^^ is partner to change all to upper case
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.