Scripting School Assignment renaming files without extension .old to have .old Announcing the...

The logistics of corpse disposal

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

What does F' and F" mean?

51k Euros annually for a family of 4 in Berlin: Is it enough?

What does this icon in iOS Stardew Valley mean?

Gordon Ramsay Pudding Recipe

How to deal with a team lead who never gives me credit?

At the end of Thor: Ragnarok why don't the Asgardians turn and head for the Bifrost as per their original plan?

Why is my conclusion inconsistent with the van't Hoff equation?

What exactly is a "Meth" in Altered Carbon?

What is known about the Ubaid lizard-people figurines?

Ring Automorphisms that fix 1.

What's the purpose of writing one's academic biography in the third person?

Why are both D and D# fitting into my E minor key?

How come Sam didn't become Lord of Horn Hill?

What is Wonderstone and are there any references to it pre-1982?

In predicate logic, does existential quantification (∃) include universal quantification (∀), i.e. can 'some' imply 'all'?

porting install scripts : can rpm replace apt?

How do pianists reach extremely loud dynamics?

Using et al. for a last / senior author rather than for a first author

Using audio cues to encourage good posture

Why light coming from distant stars is not discrete?

Should I use a zero-interest credit card for a large one-time purchase?



Scripting School Assignment renaming files without extension .old to have .old



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionSecurity implications of forgetting to quote a variable in bash/POSIX shellsWhen is double-quoting necessary?grep command giving errorCreating a function that reads off an input list of filesusing grep exact match, using a list file to look into another fileLoop to apply command to 300 files in a directory and rename the output including the original input file name plus new textPiping sed to grep does not seem to work as expectedBegin for loop every time where it ended lastDelete all files that do not have target string?Check if a file contains an exact match string from another file using grepNeed to iterate through subdirectories, concatenating files, with an iterative numberCount values of dict-like object in multiple files





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-1















The goal of the script is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is to do it with a for loop piped with grep -v to check match filenames not containing .old. From what I have read this is not proper technique, however this assignment is submitted virtually and will not be accepted unless the code is written in this way and returns the correct values.



The tricky part is that the files needing to be renamed are file1 file2.old file3old and file4.old. The only issue I'm having with different iterations of the code is that either it will completely ignore the file3old or it will rename it to file3old.old. Another problem is that I can iterate the code to change file3old to file3.old but the loop checks all of the files and displays an error saying that file2.old and file4.old already exist.



Here is the code I have so far:



!#/bin/bash
filename=$1
for filename in $(ls $1 | grep -v '.old$')
do
mv $1/"$filename" $1/"file"$#".old"
done









share|improve this question









New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • why would you rename file3old to file3.old?

    – jsotola
    4 hours ago











  • yes it needs to be renamed to file3.old

    – matthew2196
    3 hours ago











  • can you post the sample contents of the filename and expected output

    – Kamaraj
    1 hour ago


















-1















The goal of the script is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is to do it with a for loop piped with grep -v to check match filenames not containing .old. From what I have read this is not proper technique, however this assignment is submitted virtually and will not be accepted unless the code is written in this way and returns the correct values.



The tricky part is that the files needing to be renamed are file1 file2.old file3old and file4.old. The only issue I'm having with different iterations of the code is that either it will completely ignore the file3old or it will rename it to file3old.old. Another problem is that I can iterate the code to change file3old to file3.old but the loop checks all of the files and displays an error saying that file2.old and file4.old already exist.



Here is the code I have so far:



!#/bin/bash
filename=$1
for filename in $(ls $1 | grep -v '.old$')
do
mv $1/"$filename" $1/"file"$#".old"
done









share|improve this question









New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • why would you rename file3old to file3.old?

    – jsotola
    4 hours ago











  • yes it needs to be renamed to file3.old

    – matthew2196
    3 hours ago











  • can you post the sample contents of the filename and expected output

    – Kamaraj
    1 hour ago














-1












-1








-1








The goal of the script is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is to do it with a for loop piped with grep -v to check match filenames not containing .old. From what I have read this is not proper technique, however this assignment is submitted virtually and will not be accepted unless the code is written in this way and returns the correct values.



The tricky part is that the files needing to be renamed are file1 file2.old file3old and file4.old. The only issue I'm having with different iterations of the code is that either it will completely ignore the file3old or it will rename it to file3old.old. Another problem is that I can iterate the code to change file3old to file3.old but the loop checks all of the files and displays an error saying that file2.old and file4.old already exist.



Here is the code I have so far:



!#/bin/bash
filename=$1
for filename in $(ls $1 | grep -v '.old$')
do
mv $1/"$filename" $1/"file"$#".old"
done









share|improve this question









New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












The goal of the script is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is to do it with a for loop piped with grep -v to check match filenames not containing .old. From what I have read this is not proper technique, however this assignment is submitted virtually and will not be accepted unless the code is written in this way and returns the correct values.



The tricky part is that the files needing to be renamed are file1 file2.old file3old and file4.old. The only issue I'm having with different iterations of the code is that either it will completely ignore the file3old or it will rename it to file3old.old. Another problem is that I can iterate the code to change file3old to file3.old but the loop checks all of the files and displays an error saying that file2.old and file4.old already exist.



Here is the code I have so far:



!#/bin/bash
filename=$1
for filename in $(ls $1 | grep -v '.old$')
do
mv $1/"$filename" $1/"file"$#".old"
done






grep scripting mv for loop-device






share|improve this question









New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 46 mins ago









Rui F Ribeiro

42.1k1484142




42.1k1484142






New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 hours ago









matthew2196matthew2196

1




1




New contributor




matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






matthew2196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • why would you rename file3old to file3.old?

    – jsotola
    4 hours ago











  • yes it needs to be renamed to file3.old

    – matthew2196
    3 hours ago











  • can you post the sample contents of the filename and expected output

    – Kamaraj
    1 hour ago



















  • why would you rename file3old to file3.old?

    – jsotola
    4 hours ago











  • yes it needs to be renamed to file3.old

    – matthew2196
    3 hours ago











  • can you post the sample contents of the filename and expected output

    – Kamaraj
    1 hour ago

















why would you rename file3old to file3.old?

– jsotola
4 hours ago





why would you rename file3old to file3.old?

– jsotola
4 hours ago













yes it needs to be renamed to file3.old

– matthew2196
3 hours ago





yes it needs to be renamed to file3.old

– matthew2196
3 hours ago













can you post the sample contents of the filename and expected output

– Kamaraj
1 hour ago





can you post the sample contents of the filename and expected output

– Kamaraj
1 hour ago










1 Answer
1






active

oldest

votes


















0














prename (check out the -n option);



rename 's/([0-9])[^0-9]*$/$1.old/g' *


for (will not work on large sets of files);



for F in * ; do
N="$(echo "$F" | perl -pe 's/.?old$//g' ).old";
if [ "$F" == "$N" ] ; then
continue;
fi
mv "$F" "$N"
done


grep pipe (use -print0 if you want to deal with n in file names);



while read -r F ; do
N="$(echo "$F" | perl -pe 's/old$//g' ).old";
mv "$F" "$N"
done < <(find . -type f | grep -Pv ".old$")





share|improve this answer


























  • Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

    – matthew2196
    2 hours ago












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
});


}
});






matthew2196 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512891%2fscripting-school-assignment-renaming-files-without-extension-old-to-have-old%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









0














prename (check out the -n option);



rename 's/([0-9])[^0-9]*$/$1.old/g' *


for (will not work on large sets of files);



for F in * ; do
N="$(echo "$F" | perl -pe 's/.?old$//g' ).old";
if [ "$F" == "$N" ] ; then
continue;
fi
mv "$F" "$N"
done


grep pipe (use -print0 if you want to deal with n in file names);



while read -r F ; do
N="$(echo "$F" | perl -pe 's/old$//g' ).old";
mv "$F" "$N"
done < <(find . -type f | grep -Pv ".old$")





share|improve this answer


























  • Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

    – matthew2196
    2 hours ago
















0














prename (check out the -n option);



rename 's/([0-9])[^0-9]*$/$1.old/g' *


for (will not work on large sets of files);



for F in * ; do
N="$(echo "$F" | perl -pe 's/.?old$//g' ).old";
if [ "$F" == "$N" ] ; then
continue;
fi
mv "$F" "$N"
done


grep pipe (use -print0 if you want to deal with n in file names);



while read -r F ; do
N="$(echo "$F" | perl -pe 's/old$//g' ).old";
mv "$F" "$N"
done < <(find . -type f | grep -Pv ".old$")





share|improve this answer


























  • Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

    – matthew2196
    2 hours ago














0












0








0







prename (check out the -n option);



rename 's/([0-9])[^0-9]*$/$1.old/g' *


for (will not work on large sets of files);



for F in * ; do
N="$(echo "$F" | perl -pe 's/.?old$//g' ).old";
if [ "$F" == "$N" ] ; then
continue;
fi
mv "$F" "$N"
done


grep pipe (use -print0 if you want to deal with n in file names);



while read -r F ; do
N="$(echo "$F" | perl -pe 's/old$//g' ).old";
mv "$F" "$N"
done < <(find . -type f | grep -Pv ".old$")





share|improve this answer















prename (check out the -n option);



rename 's/([0-9])[^0-9]*$/$1.old/g' *


for (will not work on large sets of files);



for F in * ; do
N="$(echo "$F" | perl -pe 's/.?old$//g' ).old";
if [ "$F" == "$N" ] ; then
continue;
fi
mv "$F" "$N"
done


grep pipe (use -print0 if you want to deal with n in file names);



while read -r F ; do
N="$(echo "$F" | perl -pe 's/old$//g' ).old";
mv "$F" "$N"
done < <(find . -type f | grep -Pv ".old$")






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 3 hours ago









user1133275user1133275

3,7741924




3,7741924













  • Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

    – matthew2196
    2 hours ago



















  • Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

    – matthew2196
    2 hours ago

















Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

– matthew2196
2 hours ago





Unfortunately this doesn't work with the online submission, it only wants code formatted with a while loop with ls piped into a grep -v argument.

– matthew2196
2 hours ago










matthew2196 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















matthew2196 is a new contributor. Be nice, and check out our Code of Conduct.













matthew2196 is a new contributor. Be nice, and check out our Code of Conduct.












matthew2196 is a new contributor. Be nice, and check out our Code of Conduct.
















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512891%2fscripting-school-assignment-renaming-files-without-extension-old-to-have-old%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...