-
regex help
since I'm completely at a loss with regex [ yup, I rarely do any shell scripting so I have never actually needed to use one before ]
does anyone know what the regex would be to append 000 to any file in the searched folder that has an extention?
By extention, I mean any file that has a . in the name.
-
So you want this in say a bash script and not a C or C++ program?
> does anyone know what the regex would be to append 000 to any file
Is this appended to the file, or appended to the filename ( foo.c -> foo.c000 )
-
bash, perl, python, php..
or any other valid scripting language for *x :)
which is also c and c++. :D
appended to the filename. foo.bar >> foo.bar000
[ zero not capitol o .. I do miss the old differentiated zero of system fonts ]
it's not the entire script or program, just the regex that would do the scan and exchange.
I know that perl or bash is much simpler than c or c++ for this. my neighbour actually asked me how and I just don't know regex use to show him.
-
Regex doesn't do that. You want Bash replacement expressions. Something like $(listing#.000) or something - I never remember the syntax. It's curly braces, I know that. How do I trick the code tags script? The new one isn't fooled by a pair of code tags somewhere else in the post.
info bash
should provide more information.
-
regular expressions won't allow you to scan for a specific item then make a change to it ?
someone better tell the apache mod_rewrite developers that, since that is exactly what it does. :D
and all the spam detection software, that uses regex to perform a scan then trigger an action. :D
I know the regex won't make thealteration, it is only the scanning criteria.
-
Well, you made my point.
And of course, regex for searching for a single dot is quite some overkill.
-
Regex?
Just use bash(1)'s for:
Code:
$ for f in *.*; do mv $f ${f}000; done
-
Regex can look VERY cryptic, but once you learn it it is amazing :D.
I agree that it is overkill for this, but do some parsers in Perl and you will learn to love Regex. It is awesome how easy it makes some things.
-
zx-1, thanks, I don't do a lot of shell scripting work. :)
Wraithan,
I know, it took me 3 hours to fully understand a rewrite rule regex. reading the docs on regex and having the rule there to dissect it with the docs. I still don't understand regex well enough to trust my own coding on it. Until I do, I'll not hesitate to ask for help when I need regex.
It always looks cryptic, but it allows for extremely clean and elegant code that does the task perfectly and quickly. A single iteration through something rather than multiple iterations.