change multiple file name with script and use the previous names
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
-2
down vote
favorite
I want to change multiple file names with their previous names using a script, for example change file names as below:
2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt
2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt
command-line bash scripts
add a comment |Â
up vote
-2
down vote
favorite
I want to change multiple file names with their previous names using a script, for example change file names as below:
2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt
2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt
command-line bash scripts
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I want to change multiple file names with their previous names using a script, for example change file names as below:
2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt
2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt
command-line bash scripts
I want to change multiple file names with their previous names using a script, for example change file names as below:
2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt
2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt
command-line bash scripts
command-line bash scripts
edited Feb 13 at 12:59
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
20k55795
20k55795
asked Feb 13 at 12:22
MN65
11
11
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
One way with rename
:
rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
In -n
ono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.
An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:
rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *
Example run
$ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)
add a comment |Â
up vote
2
down vote
Bash script(script.sh) to rename multiple files.
#!/bin/bash
INPUT="$1"
IFS=,
[ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
while read old_name new_name
do
rename "$old_name" "$new_name" # mv or rename
done < "$INPUT"
Input.txt file format:
old_name1.txt,new_name1.txt
old_name2.txt,new_name2.txt
Use:
bash script.sh input.txt
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
One way with rename
:
rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
In -n
ono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.
An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:
rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *
Example run
$ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)
add a comment |Â
up vote
2
down vote
accepted
One way with rename
:
rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
In -n
ono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.
An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:
rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *
Example run
$ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
One way with rename
:
rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
In -n
ono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.
An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:
rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *
Example run
$ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)
One way with rename
:
rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
In -n
ono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.
An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:
rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *
Example run
$ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)
edited Feb 13 at 13:37
answered Feb 13 at 12:51
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
20k55795
20k55795
add a comment |Â
add a comment |Â
up vote
2
down vote
Bash script(script.sh) to rename multiple files.
#!/bin/bash
INPUT="$1"
IFS=,
[ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
while read old_name new_name
do
rename "$old_name" "$new_name" # mv or rename
done < "$INPUT"
Input.txt file format:
old_name1.txt,new_name1.txt
old_name2.txt,new_name2.txt
Use:
bash script.sh input.txt
add a comment |Â
up vote
2
down vote
Bash script(script.sh) to rename multiple files.
#!/bin/bash
INPUT="$1"
IFS=,
[ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
while read old_name new_name
do
rename "$old_name" "$new_name" # mv or rename
done < "$INPUT"
Input.txt file format:
old_name1.txt,new_name1.txt
old_name2.txt,new_name2.txt
Use:
bash script.sh input.txt
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Bash script(script.sh) to rename multiple files.
#!/bin/bash
INPUT="$1"
IFS=,
[ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
while read old_name new_name
do
rename "$old_name" "$new_name" # mv or rename
done < "$INPUT"
Input.txt file format:
old_name1.txt,new_name1.txt
old_name2.txt,new_name2.txt
Use:
bash script.sh input.txt
Bash script(script.sh) to rename multiple files.
#!/bin/bash
INPUT="$1"
IFS=,
[ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
while read old_name new_name
do
rename "$old_name" "$new_name" # mv or rename
done < "$INPUT"
Input.txt file format:
old_name1.txt,new_name1.txt
old_name2.txt,new_name2.txt
Use:
bash script.sh input.txt
edited Feb 13 at 14:12
terdonâ¦
62.2k12128205
62.2k12128205
answered Feb 13 at 12:27
![](https://i.stack.imgur.com/7fkOr.jpg?s=32&g=1)
![](https://i.stack.imgur.com/7fkOr.jpg?s=32&g=1)
arupgsh
25217
25217
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1005789%2fchange-multiple-file-name-with-script-and-use-the-previous-names%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password