I am quite new to awk
and linux scripting. Need your help to modify the file generation:
Current output: A20211126.0200+0500-0215+0500.xml
Expected output: A20211126.0200-0215.xml
for all the files in a particular directory.
I want to use a crontab as well to ensure the file names with +0500 is checked and if found then convert the same as mentioned in the expected output.
Thanks All.
I did the following to achieve the desired output.
for file in *.xml ; do mv $file ${file//+0500/} ; done
now I am able to remove the +0500 part
If you have perl prename available, then you can use rename
to achieve this with regex.
If it is not available, you can install it via perls cpan
(similar to pip) and then replace util-linux version that should be installed by default.
Perl
will need to be available to use CPAN
$ ls
A20211126.0200+0500-0215+0500.xml
$ rename 's/([^+]*)[^-]*([^+]*)[^.]*(.*)/$1$2$3/' *.xml
$ ls
A20211126.0200-0215.xml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.