Swap words and reformat date in a filename The 2019 Stack Overflow Developer Survey Results Are InWhat's with all the renames: prename, rename, file-rename?Appending a current date from a variable to a filenameIncluding a date in a filenameBatch rename image files by age plus add date and variable to filenameHow to exchange words in a filename using the shell?Reformat date stringRenaming a file the moment it appears in a folderinserting modified date into filename - 2 casesSwap 2 words without using 3rd wordValidating File Name format in linux shellpass arguments to the date command in LHS of sed
Why did Acorn's A3000 have red function keys?
How to type this arrow in math mode?
Output the Arecibo Message
Did Section 31 appear in Star Trek: The Next Generation?
Building a conditional check constraint
What is the motivation for a law requiring 2 parties to consent for recording a conversation
What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?
Identify This Plant (Flower)
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
How to notate time signature switching consistently every measure
What is the most effective way of iterating a std::vector and why?
Shouldn't "much" here be used instead of "more"?
What did it mean to "align" a radio?
Falsification in Math vs Science
One word riddle: Vowel in the middle
Have you ever entered Singapore using a different passport or name?
Identify boardgame from Big movie
Did 3000BC Egyptians use meteoric iron weapons?
Statement true because not provable
What is the accessibility of a package's `Private` context variables?
What is the meaning of Triage in Cybersec world?
FPGA - DIY Programming
How come people say “Would of”?
What is the meaning of the verb "bear" in this context?
Swap words and reformat date in a filename
The 2019 Stack Overflow Developer Survey Results Are InWhat's with all the renames: prename, rename, file-rename?Appending a current date from a variable to a filenameIncluding a date in a filenameBatch rename image files by age plus add date and variable to filenameHow to exchange words in a filename using the shell?Reformat date stringRenaming a file the moment it appears in a folderinserting modified date into filename - 2 casesSwap 2 words without using 3rd wordValidating File Name format in linux shellpass arguments to the date command in LHS of sed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have several recordings with a file-name schema like this
%year%month%day-%hour%minute%second__%phonenumber.amr
e.g.:
20190212-112007__+313206601234.amr
I want to swap words to obtain:
%phonenumber_%day-%month-%year_%hour-%minute-%second.amr
e.g.:
+313206601234__12-02-2019_11-20-07.amr
I know I can use sed utility but its syntax is like an archaic language, plus I'm confused about the use of both [0-9] and . for substitution.
sed rename
add a comment |
I have several recordings with a file-name schema like this
%year%month%day-%hour%minute%second__%phonenumber.amr
e.g.:
20190212-112007__+313206601234.amr
I want to swap words to obtain:
%phonenumber_%day-%month-%year_%hour-%minute-%second.amr
e.g.:
+313206601234__12-02-2019_11-20-07.amr
I know I can use sed utility but its syntax is like an archaic language, plus I'm confused about the use of both [0-9] and . for substitution.
sed rename
The archaic language is regular expressions. Howeversedif for file content and streams.rename(the Larry Wall version), issedfor file-names.
– ctrl-alt-delor
Apr 7 at 10:14
add a comment |
I have several recordings with a file-name schema like this
%year%month%day-%hour%minute%second__%phonenumber.amr
e.g.:
20190212-112007__+313206601234.amr
I want to swap words to obtain:
%phonenumber_%day-%month-%year_%hour-%minute-%second.amr
e.g.:
+313206601234__12-02-2019_11-20-07.amr
I know I can use sed utility but its syntax is like an archaic language, plus I'm confused about the use of both [0-9] and . for substitution.
sed rename
I have several recordings with a file-name schema like this
%year%month%day-%hour%minute%second__%phonenumber.amr
e.g.:
20190212-112007__+313206601234.amr
I want to swap words to obtain:
%phonenumber_%day-%month-%year_%hour-%minute-%second.amr
e.g.:
+313206601234__12-02-2019_11-20-07.amr
I know I can use sed utility but its syntax is like an archaic language, plus I'm confused about the use of both [0-9] and . for substitution.
sed rename
sed rename
edited Apr 7 at 14:33
Rui F Ribeiro
42k1483142
42k1483142
asked Apr 7 at 9:03
mattia.b89mattia.b89
866421
866421
The archaic language is regular expressions. Howeversedif for file content and streams.rename(the Larry Wall version), issedfor file-names.
– ctrl-alt-delor
Apr 7 at 10:14
add a comment |
The archaic language is regular expressions. Howeversedif for file content and streams.rename(the Larry Wall version), issedfor file-names.
– ctrl-alt-delor
Apr 7 at 10:14
The archaic language is regular expressions. However
sed if for file content and streams. rename (the Larry Wall version), is sed for file-names.– ctrl-alt-delor
Apr 7 at 10:14
The archaic language is regular expressions. However
sed if for file content and streams. rename (the Larry Wall version), is sed for file-names.– ctrl-alt-delor
Apr 7 at 10:14
add a comment |
1 Answer
1
active
oldest
votes
It's all about using captured groups of digits, and putting groups at desired places to get the required name:
sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/'
-Eenables ERE (Extended Regular Expressions)[[:digit:]]matches a locale-aware digitNmatchesNnumber of preceding token e.g.[[:digit:]]2matches 2 digits; this can also be a range e.g.[[:digit:]]2,4matches 2 to 4 digits
Example:
% sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/' <<<'20190212-112007__+313206601234.amr'
+313206601234__12-02-2019_11-20-07.amr
@mattia.b89: With prename (Perl's standalone rename command):prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove-n.
– Cyrus
Apr 7 at 11:06
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511010%2fswap-words-and-reformat-date-in-a-filename%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's all about using captured groups of digits, and putting groups at desired places to get the required name:
sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/'
-Eenables ERE (Extended Regular Expressions)[[:digit:]]matches a locale-aware digitNmatchesNnumber of preceding token e.g.[[:digit:]]2matches 2 digits; this can also be a range e.g.[[:digit:]]2,4matches 2 to 4 digits
Example:
% sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/' <<<'20190212-112007__+313206601234.amr'
+313206601234__12-02-2019_11-20-07.amr
@mattia.b89: With prename (Perl's standalone rename command):prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove-n.
– Cyrus
Apr 7 at 11:06
add a comment |
It's all about using captured groups of digits, and putting groups at desired places to get the required name:
sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/'
-Eenables ERE (Extended Regular Expressions)[[:digit:]]matches a locale-aware digitNmatchesNnumber of preceding token e.g.[[:digit:]]2matches 2 digits; this can also be a range e.g.[[:digit:]]2,4matches 2 to 4 digits
Example:
% sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/' <<<'20190212-112007__+313206601234.amr'
+313206601234__12-02-2019_11-20-07.amr
@mattia.b89: With prename (Perl's standalone rename command):prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove-n.
– Cyrus
Apr 7 at 11:06
add a comment |
It's all about using captured groups of digits, and putting groups at desired places to get the required name:
sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/'
-Eenables ERE (Extended Regular Expressions)[[:digit:]]matches a locale-aware digitNmatchesNnumber of preceding token e.g.[[:digit:]]2matches 2 digits; this can also be a range e.g.[[:digit:]]2,4matches 2 to 4 digits
Example:
% sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/' <<<'20190212-112007__+313206601234.amr'
+313206601234__12-02-2019_11-20-07.amr
It's all about using captured groups of digits, and putting groups at desired places to get the required name:
sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/'
-Eenables ERE (Extended Regular Expressions)[[:digit:]]matches a locale-aware digitNmatchesNnumber of preceding token e.g.[[:digit:]]2matches 2 digits; this can also be a range e.g.[[:digit:]]2,4matches 2 to 4 digits
Example:
% sed -E 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/7__3-2-1_4-5-6/' <<<'20190212-112007__+313206601234.amr'
+313206601234__12-02-2019_11-20-07.amr
edited Apr 7 at 11:16
answered Apr 7 at 9:11
heemaylheemayl
36.3k378108
36.3k378108
@mattia.b89: With prename (Perl's standalone rename command):prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove-n.
– Cyrus
Apr 7 at 11:06
add a comment |
@mattia.b89: With prename (Perl's standalone rename command):prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove-n.
– Cyrus
Apr 7 at 11:06
@mattia.b89: With prename (Perl's standalone rename command):
prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove -n.– Cyrus
Apr 7 at 11:06
@mattia.b89: With prename (Perl's standalone rename command):
prename -n 's/^([[:digit:]]4)([[:digit:]]2)([[:digit:]]2)-([[:digit:]]2)([[:digit:]]2)([[:digit:]]2)__(+[[:digit:]]+)/$7__$3-$2-$1_$4-$5-$6/' *.amr. If everything looks fine, remove -n.– Cyrus
Apr 7 at 11:06
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511010%2fswap-words-and-reformat-date-in-a-filename%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The archaic language is regular expressions. However
sedif for file content and streams.rename(the Larry Wall version), issedfor file-names.– ctrl-alt-delor
Apr 7 at 10:14