Script bash
- grzesiekzxr
- Offline
- Senior Member
-
- Posts: 75
- Thank you received: 0
#!/bin/bash
for d in $*; do
for f in $(ls $d/*.dat); do
echo $(date) $(mv -v $f ${f%.dat}.txt)
done
done
#!/bin/bash
for d in $*; do
for f in $(ls $d/*.ngc); do
echo $(ngc) $(mv -v $f ${f%.ngc}.inv)
done
done
Whether it might work ?
regards.
Please Log in or Create an account to join the conversation.
Whether it might work ?
Try it
Seems a rather convoluted way to change the extension of a file, but if it works..................
Please Log in or Create an account to join the conversation.
- grzesiekzxr
- Offline
- Senior Member
-
- Posts: 75
- Thank you received: 0
regards.
Please Log in or Create an account to join the conversation.
rename 's/\.dat$/\.ngc/' *dat
JT
Please Log in or Create an account to join the conversation.
It now takes perlexpr, which basically means regex
So you can do
rename 's/\.ngc/\.inv/' *.ngc
which explains why some of my scripts stopped working properly
![;) ;)](/media/kunena/emoticons/wink.png)
regards
Please Log in or Create an account to join the conversation.
The tricky part in the middle is a Perl substitution with regular expressions, highlighted below:
rename -v ’s/\.htm$/\.html/’ *.htm
Tip: There is an intro to Perl regular expressions here.
Basically the "s" means substitute. The syntax is s/old/new/ — substitute the old with the new.
A . (period) has a special meaning in a regular expression — it means "match any character". We don't want to match any character in the example above. It should match only a period. The backslash is a way to "escape" the regular expression meaning of "any character" and just read it as a normal period.
The $ means the end of the string. \.htm$ means that it will match .htm but not .html.
It's fairly basic — substitute .htm with .html:
's/\.htm$/\.html/'
The last part of the command, highlighted below, means to apply the rename command to every file that ends with .htm (the * is a wildcard).
rename -v ’s/\.htm$/\.html/’ *.htm
JT
Please Log in or Create an account to join the conversation.
On Debian at least, rename seems to have been updated.
It now takes perlexpr, which basically means regex
So you can do
rename 's/\.ngc/\.inv/' *.ngc
which explains why some of my scripts stopped working properly
regards
It takes a perlexpr on Ubuntu 10.04 too.
JT
Please Log in or Create an account to join the conversation.
It takes a perlexpr on Ubuntu 10.04 too.
It had a 26.09.2014 datestamp on the manpage and only showed the regex type examples, so I assumed it had changed.
My previous scripts used something much more like your original syntax example
A couple of scripts I have which used it, didn't work properly last time I tried them, but that may have been something else, they were quite complex
audio and video conversion scripts using mencoder.
I just used one that used ffmpeg instead I think, so never got to the root of it
![:S :S](/media/kunena/emoticons/dizzy.png)
regards
Please Log in or Create an account to join the conversation.
- grzesiekzxr
- Offline
- Senior Member
-
- Posts: 75
- Thank you received: 0
ArcEye;
Thank you
BigJohnT,
Just trying put it in my code but I have an error in terminal
![:unsure: :unsure:](/media/kunena/emoticons/unsure.png)
Can't rename *.ngc *.inv: Nie ma takiego pliku ani katalogu => there is no such file and catalog.
#!/bin/bash
echo "M102 called"
rename 's/\.ngc/\.inv/' *.ngc
axis-remote --clear;
axis-remote --mdi 'G55#5381 = -1' ;
axis-remote --reload &
exit 0
I made a mistake somewhere.
What is the proper way?
regards.
Please Log in or Create an account to join the conversation.
Can't rename *.ngc *.inv: Nie ma takiego pliku ani katalogu => there is no such file and catalog.
The line assumes you are in the directory containing those ngc files
If not you have to explicitly cd to it first.
By default a script launched by your user is likely to start in your home dir.
Please Log in or Create an account to join the conversation.