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.
What is it that is determining what you want to remove? The last 4 characters? The last . and everything after it? The first two strings separated by dots are kept and everything else after is removed?
What is it that is determining what you want to remove? The last 4 characters? The last . and everything after it? The first two strings separated by dots are kept and everything else after is removed?
Let us know,
Forrest
There will always be a file thats starts with foo, followed by 3 numbers, then .txt.gpg. (ie: foo123.txt.gpg, foo245.txt.gpg, foo452.txt.gpg).
I need a script to see if foo* exists, if so, remove the .gpg from the end.
I'm assuming your shell is bash. If so, have a look at the man page for bash and search for "Parameter Expansion":
Code:
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pat-
tern matches a trailing portion of the expanded value of parameter, then the result
of the expansion is the expanded value of parameter with the shortest matching pat-
tern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted. If
parameter is @ or *, the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list. If parameter is an array
variable subscripted with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant list.
I'm assuming your shell is bash. If so, have a look at the man page for bash and search for "Parameter Expansion":
Code:
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pat-
tern matches a trailing portion of the expanded value of parameter, then the result
of the expansion is the expanded value of parameter with the shortest matching pat-
tern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted. If
parameter is @ or *, the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list. If parameter is an array
variable subscripted with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant list.
Thanks for everyones responses. We ended up doing this....
Code:
for i in `find /tmp/ -name foo*pgp -print0`; do
newvar=`echo $i | sed s/.pgp//g`
mv $i $newvar
done
Now if someone googles with the same question, they have multiple options.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.