Using a single / in ${VARIABLE} , removes the following pattern, including *?. expansion, unless quoted or escaped
Using two // will replace the the 1nd pattern string with the 2nd pattern string.
Example:
echo "${VARIABLE/$SEARCH/$REPLACE}"
However, this will only apply to the first found occourence!
In a filename matching pattern, . matches a period. But in a basic regular expression (which is what is used in sed ), an unadorned . matches any single character.
A few things you might want think about: \(\) : you are telling to capture the matched part. Since you are not using it, it is a waste of effort. g : matching as many times as possible in a line, is not the intention in this case.
user@host:~/unix$ ls g*
g-82.text.text1.fr.worker1 g-xx.yyyyyy.zzzz.fr.worker2
g-xx.Africa.zzzz.fr.worker3
user@host:~/unix$ ls g* | sed "s/\(.*\)\(.fr.*\)/\1/g"
g-82.text.text1
g-xx.Africa.zzzz
g-xx.yyyyyy.zzzz
So \1 is what you want and \2 (which is not used) is the extension being removed from the ls output.
In post #3 in this thread, I suggested simple, clear shell, sed and awk scripts that did exactly what was requested. Since then there have been several proposals that, although they work with the sample provided, would not work in the general case. Peasant's proposal above is more complicated than the sed suggestion I made earlier:
sed 's/[.]fr[.].*//' file
and, it works fine as long as the final string after the .fr. in the filenames being processed is literally worker followed by a string of digits. But, it fails if the two characters fr can ever appear anywhere in the filenames after the .fr. such as:
g-82.text.text1.fr.Alfred_Jones
With the sparse specification of the allowed filename format, we don't know if this is a problem in this case or not.
We assume that you realize that the requirements you have presented here are completely different from the requirements you presented in post #1 in this thread (where the request was to remove .fr. and everything following it). But, yes, with these new requirements, the above awk script does what you want.
It's easier for me to use a single construct in a BRE or ERE that never changes depending on context.
All of the following commands remove the 1st two adjacent periods from each input line processed:
sed 's/\.\.//'
awk '{sub("\\.\\.","")}1'
awk -v RE='\\\\.\\\\.' '{sub(RE,"")}1'
sed 's/[.][.]//'
awk '{sub("[.][.]","")}1'
awk -v RE='[.][.]' '{sub(RE,"")}1'
Note the varying number of backslashes required when using escapes (one, two , or four for each escaped period), depending on context. But when using the character class expression, the same string works in all three cases.