Script bash

More
11 Dec 2014 18:40 - 11 Dec 2014 18:47 #53910 by grzesiekzxr
Replied by grzesiekzxr on topic Script bash
It is orginal what I found:



#!/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.
Last edit: 11 Dec 2014 18:47 by grzesiekzxr.

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 19:29 #53912 by ArcEye
Replied by ArcEye on topic Script bash

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.

More
11 Dec 2014 20:43 - 11 Dec 2014 20:43 #53915 by grzesiekzxr
Replied by grzesiekzxr on topic Script bash
Could you suggest me simplest script changing extension?
regards.
Last edit: 11 Dec 2014 20:43 by grzesiekzxr.

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 20:54 - 11 Dec 2014 21:20 #53916 by BigJohnT
Replied by BigJohnT on topic Script bash
You could use rename.
rename 's/\.dat$/\.ngc/' *dat

JT
Last edit: 11 Dec 2014 21:20 by BigJohnT.

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 21:06 #53917 by ArcEye
Replied by ArcEye on topic Script bash
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

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 21:18 #53920 by BigJohnT
Replied by BigJohnT on topic Script bash
I found this explanation of perlexp on the web.

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.

More
11 Dec 2014 21:21 #53921 by BigJohnT
Replied by BigJohnT on topic Script bash

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
The following user(s) said Thank You: grzesiekzxr

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 22:25 #53925 by ArcEye
Replied by ArcEye on topic Script bash
BJT wrote:

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

regards
The following user(s) said Thank You: grzesiekzxr

Please Log in or Create an account to join the conversation.

More
11 Dec 2014 23:15 #53927 by grzesiekzxr
Replied by grzesiekzxr on topic Script bash
Thank you
ArcEye;
Thank you
BigJohnT,

Just trying put it in my code but I have an error in terminal :unsure: .
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.

More
11 Dec 2014 23:21 #53928 by ArcEye
Replied by ArcEye on topic Script bash

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.

Time to create page: 0.114 seconds
Powered by Kunena Forum