Bash String manipulation when string contains parentheses Announcing the arrival of Valued...

Old style "caution" boxes

Is there a kind of relay only consumes power when switching?

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

How to deal with a team lead who never gives me credit?

Wu formula for manifolds with boundary

What do you call the main part of a joke?

Circuit to "zoom in" on mV fluctuations of a DC signal?

First console to have temporary backward compatibility

If a VARCHAR(MAX) column is included in an index, is the entire value always stored in the index page(s)?

How do I find out the mythology and history of my Fortress?

Can an alien society believe that their star system is the universe?

Did MS DOS itself ever use blinking text?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Is it a good idea to use CNN to classify 1D signal?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

How to convince students of the implication truth values?

What is the meaning of the simile “quick as silk”?

Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?

Around usage results

What is homebrew?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

What does "lightly crushed" mean for cardamon pods?

Is there such thing as an Availability Group failover trigger?



Bash String manipulation when string contains parentheses



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionrenaming files without the **rename** commandBash - Continuous String Manipulationmoving a (file | directory) while avoiding filename collisionsPiping bash string manipulationBash regex string manipulation bugReturning a variable from a functionBash script to select files to zip/unzipSearch directories for multi line stringBash Completion for Paths and Nothing Elserename a file removing part of the filename bash script





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have a directory full of files with the name template



xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip


The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are uncompressed.



I am creating a processing script but I want to name that common file a name associated with its source zip and I'm checking the method:



for f in $(ls xxx*)
do
uniquename="${f%%(wrx.*zip}"
done


I can't figure out how to strip that opening parens from the string.



Is that possible with the bash string manipulation the way I am doing it?
That is to say, it does not work. What do I need to add or remove so that it does work?










share|improve this question

























  • What exactly is the problem here? Consider adding example input and the corresponding desired output.

    – igal
    7 hours ago


















0















I have a directory full of files with the name template



xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip


The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are uncompressed.



I am creating a processing script but I want to name that common file a name associated with its source zip and I'm checking the method:



for f in $(ls xxx*)
do
uniquename="${f%%(wrx.*zip}"
done


I can't figure out how to strip that opening parens from the string.



Is that possible with the bash string manipulation the way I am doing it?
That is to say, it does not work. What do I need to add or remove so that it does work?










share|improve this question

























  • What exactly is the problem here? Consider adding example input and the corresponding desired output.

    – igal
    7 hours ago














0












0








0








I have a directory full of files with the name template



xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip


The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are uncompressed.



I am creating a processing script but I want to name that common file a name associated with its source zip and I'm checking the method:



for f in $(ls xxx*)
do
uniquename="${f%%(wrx.*zip}"
done


I can't figure out how to strip that opening parens from the string.



Is that possible with the bash string manipulation the way I am doing it?
That is to say, it does not work. What do I need to add or remove so that it does work?










share|improve this question
















I have a directory full of files with the name template



xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip


The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are uncompressed.



I am creating a processing script but I want to name that common file a name associated with its source zip and I'm checking the method:



for f in $(ls xxx*)
do
uniquename="${f%%(wrx.*zip}"
done


I can't figure out how to strip that opening parens from the string.



Is that possible with the bash string manipulation the way I am doing it?
That is to say, it does not work. What do I need to add or remove so that it does work?







bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago







Ken Ingram

















asked 7 hours ago









Ken IngramKen Ingram

1235




1235













  • What exactly is the problem here? Consider adding example input and the corresponding desired output.

    – igal
    7 hours ago



















  • What exactly is the problem here? Consider adding example input and the corresponding desired output.

    – igal
    7 hours ago

















What exactly is the problem here? Consider adding example input and the corresponding desired output.

– igal
7 hours ago





What exactly is the problem here? Consider adding example input and the corresponding desired output.

– igal
7 hours ago










1 Answer
1






active

oldest

votes


















1














Try removing the dot from your pattern, i.e.:



for f in xxx*;
do
uniquename="${f%%(wrx*zip}";
echo "${uniquename}";
done


That takes files whose names are of the form xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip and converts them to strings of the form xxx[0-9][0-9][0-9[0-9]ss. Is that what you're trying to accomplish?






share|improve this answer


























  • Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

    – Ken Ingram
    6 hours ago






  • 2





    Bash Pitfall #1

    – steeldriver
    6 hours ago











  • Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

    – Ken Ingram
    5 hours ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513102%2fbash-string-manipulation-when-string-contains-parentheses%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try removing the dot from your pattern, i.e.:



for f in xxx*;
do
uniquename="${f%%(wrx*zip}";
echo "${uniquename}";
done


That takes files whose names are of the form xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip and converts them to strings of the form xxx[0-9][0-9][0-9[0-9]ss. Is that what you're trying to accomplish?






share|improve this answer


























  • Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

    – Ken Ingram
    6 hours ago






  • 2





    Bash Pitfall #1

    – steeldriver
    6 hours ago











  • Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

    – Ken Ingram
    5 hours ago
















1














Try removing the dot from your pattern, i.e.:



for f in xxx*;
do
uniquename="${f%%(wrx*zip}";
echo "${uniquename}";
done


That takes files whose names are of the form xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip and converts them to strings of the form xxx[0-9][0-9][0-9[0-9]ss. Is that what you're trying to accomplish?






share|improve this answer


























  • Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

    – Ken Ingram
    6 hours ago






  • 2





    Bash Pitfall #1

    – steeldriver
    6 hours ago











  • Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

    – Ken Ingram
    5 hours ago














1












1








1







Try removing the dot from your pattern, i.e.:



for f in xxx*;
do
uniquename="${f%%(wrx*zip}";
echo "${uniquename}";
done


That takes files whose names are of the form xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip and converts them to strings of the form xxx[0-9][0-9][0-9[0-9]ss. Is that what you're trying to accomplish?






share|improve this answer















Try removing the dot from your pattern, i.e.:



for f in xxx*;
do
uniquename="${f%%(wrx*zip}";
echo "${uniquename}";
done


That takes files whose names are of the form xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip and converts them to strings of the form xxx[0-9][0-9][0-9[0-9]ss. Is that what you're trying to accomplish?







share|improve this answer














share|improve this answer



share|improve this answer








edited 5 hours ago









Jeff Schaller

45.1k1164147




45.1k1164147










answered 7 hours ago









igaligal

6,1761638




6,1761638













  • Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

    – Ken Ingram
    6 hours ago






  • 2





    Bash Pitfall #1

    – steeldriver
    6 hours ago











  • Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

    – Ken Ingram
    5 hours ago



















  • Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

    – Ken Ingram
    6 hours ago






  • 2





    Bash Pitfall #1

    – steeldriver
    6 hours ago











  • Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

    – Ken Ingram
    5 hours ago

















Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

– Ken Ingram
6 hours ago





Yeah that did it. I see that I was using the "." as though it were a regex, when in fact it is taken as literal.

– Ken Ingram
6 hours ago




2




2





Bash Pitfall #1

– steeldriver
6 hours ago





Bash Pitfall #1

– steeldriver
6 hours ago













Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

– Ken Ingram
5 hours ago





Interesting. I typically used expansion to select the "for" range and then when I saw "$()" was a tool I began using it. I guess I made some incorrect assumptions about why my loops wood break when filenames had whitespace or non-standard characters.

– Ken Ingram
5 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513102%2fbash-string-manipulation-when-string-contains-parentheses%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...