How to automatically change name of a new appear file in a loop while running program which has many loop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I am running my program on Unix computer.
It has 300 loop.
At each loop, it will generate 4 files, which call 1.txt, 2.txt, 3.txt, 4.txt.
And in the next loop, the new files will overwrite the old ones.
Now I want these files at the exactly loop1, loop 50, loop 100, and so on.
But I could not seat all day to wait and see the running program.
Is there any script can do a work as when these .txt files appear in running directory, rename it as a loop counter (first loop's 1.txt file will be 1_1.txt, second loop's 1.txt file will be 2_1.txt and so on...)










share|improve this question






















  • Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

    – Haxiel
    Feb 20 at 10:13












  • You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

    – ilkkachu
    Feb 20 at 10:28











  • Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

    – newbie1
    Feb 21 at 0:14















0















I am running my program on Unix computer.
It has 300 loop.
At each loop, it will generate 4 files, which call 1.txt, 2.txt, 3.txt, 4.txt.
And in the next loop, the new files will overwrite the old ones.
Now I want these files at the exactly loop1, loop 50, loop 100, and so on.
But I could not seat all day to wait and see the running program.
Is there any script can do a work as when these .txt files appear in running directory, rename it as a loop counter (first loop's 1.txt file will be 1_1.txt, second loop's 1.txt file will be 2_1.txt and so on...)










share|improve this question






















  • Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

    – Haxiel
    Feb 20 at 10:13












  • You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

    – ilkkachu
    Feb 20 at 10:28











  • Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

    – newbie1
    Feb 21 at 0:14













0












0








0








I am running my program on Unix computer.
It has 300 loop.
At each loop, it will generate 4 files, which call 1.txt, 2.txt, 3.txt, 4.txt.
And in the next loop, the new files will overwrite the old ones.
Now I want these files at the exactly loop1, loop 50, loop 100, and so on.
But I could not seat all day to wait and see the running program.
Is there any script can do a work as when these .txt files appear in running directory, rename it as a loop counter (first loop's 1.txt file will be 1_1.txt, second loop's 1.txt file will be 2_1.txt and so on...)










share|improve this question














I am running my program on Unix computer.
It has 300 loop.
At each loop, it will generate 4 files, which call 1.txt, 2.txt, 3.txt, 4.txt.
And in the next loop, the new files will overwrite the old ones.
Now I want these files at the exactly loop1, loop 50, loop 100, and so on.
But I could not seat all day to wait and see the running program.
Is there any script can do a work as when these .txt files appear in running directory, rename it as a loop counter (first loop's 1.txt file will be 1_1.txt, second loop's 1.txt file will be 2_1.txt and so on...)







shell-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 20 at 8:10









newbie1newbie1

1




1












  • Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

    – Haxiel
    Feb 20 at 10:13












  • You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

    – ilkkachu
    Feb 20 at 10:28











  • Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

    – newbie1
    Feb 21 at 0:14

















  • Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

    – Haxiel
    Feb 20 at 10:13












  • You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

    – ilkkachu
    Feb 20 at 10:28











  • Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

    – newbie1
    Feb 21 at 0:14
















Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

– Haxiel
Feb 20 at 10:13






Is your 'program' already a shell script? If so, it should be easy enough to implement a few additional conditions for the 1st, 50th and 100th invocation. Can you add the script here?

– Haxiel
Feb 20 at 10:13














You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

– ilkkachu
Feb 20 at 10:28





You have a script that creates the files? Then why not give them the correct name from the script itself? Or, you have some outside process that creates the files and you want to rename them as they appear? Can you edit your question to clarify a bit?

– ilkkachu
Feb 20 at 10:28













Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

– newbie1
Feb 21 at 0:14





Hi everyone, thanks for your comments. My program is written in Fortran but I do not have permission to change the code.

– newbie1
Feb 21 at 0:14










1 Answer
1






active

oldest

votes


















0














There are a couple of ways to do this. Which is most efficient will depend on how your script works. If you can edit your question to contain your script or a snippet at least, I'll edit this to reflect a more accurate answer for your situation.



Here's an example for loop that runs 300 times:



for i in 1..300; do
echo "test$i" > 1.txt
echo "test$i" > 2.txt
echo "test$i" > 3.txt
echo "test$i" > 4.txt
done


That, as it stands, will overwrite 1-4.txt each loop as you mention your script does.



here's a simple solution:



count=1
for i in 1..300; do
echo "test$i" > $count_1.txt
echo "test$i" > $count_2.txt
echo "test$i" > $count_3.txt
echo "test$i" > $count_4.txt
((count++))
done


This will mean that you will have files named 1_1.txt, to 300_1.txt






share|improve this answer























  • Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

    – newbie1
    Feb 21 at 0:13











  • I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

    – RobotJohnny
    Feb 21 at 10:38











  • I see. Thanks for your time.

    – newbie1
    Feb 26 at 6:54










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



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501786%2fhow-to-automatically-change-name-of-a-new-appear-file-in-a-loop-while-running-pr%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














There are a couple of ways to do this. Which is most efficient will depend on how your script works. If you can edit your question to contain your script or a snippet at least, I'll edit this to reflect a more accurate answer for your situation.



Here's an example for loop that runs 300 times:



for i in 1..300; do
echo "test$i" > 1.txt
echo "test$i" > 2.txt
echo "test$i" > 3.txt
echo "test$i" > 4.txt
done


That, as it stands, will overwrite 1-4.txt each loop as you mention your script does.



here's a simple solution:



count=1
for i in 1..300; do
echo "test$i" > $count_1.txt
echo "test$i" > $count_2.txt
echo "test$i" > $count_3.txt
echo "test$i" > $count_4.txt
((count++))
done


This will mean that you will have files named 1_1.txt, to 300_1.txt






share|improve this answer























  • Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

    – newbie1
    Feb 21 at 0:13











  • I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

    – RobotJohnny
    Feb 21 at 10:38











  • I see. Thanks for your time.

    – newbie1
    Feb 26 at 6:54















0














There are a couple of ways to do this. Which is most efficient will depend on how your script works. If you can edit your question to contain your script or a snippet at least, I'll edit this to reflect a more accurate answer for your situation.



Here's an example for loop that runs 300 times:



for i in 1..300; do
echo "test$i" > 1.txt
echo "test$i" > 2.txt
echo "test$i" > 3.txt
echo "test$i" > 4.txt
done


That, as it stands, will overwrite 1-4.txt each loop as you mention your script does.



here's a simple solution:



count=1
for i in 1..300; do
echo "test$i" > $count_1.txt
echo "test$i" > $count_2.txt
echo "test$i" > $count_3.txt
echo "test$i" > $count_4.txt
((count++))
done


This will mean that you will have files named 1_1.txt, to 300_1.txt






share|improve this answer























  • Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

    – newbie1
    Feb 21 at 0:13











  • I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

    – RobotJohnny
    Feb 21 at 10:38











  • I see. Thanks for your time.

    – newbie1
    Feb 26 at 6:54













0












0








0







There are a couple of ways to do this. Which is most efficient will depend on how your script works. If you can edit your question to contain your script or a snippet at least, I'll edit this to reflect a more accurate answer for your situation.



Here's an example for loop that runs 300 times:



for i in 1..300; do
echo "test$i" > 1.txt
echo "test$i" > 2.txt
echo "test$i" > 3.txt
echo "test$i" > 4.txt
done


That, as it stands, will overwrite 1-4.txt each loop as you mention your script does.



here's a simple solution:



count=1
for i in 1..300; do
echo "test$i" > $count_1.txt
echo "test$i" > $count_2.txt
echo "test$i" > $count_3.txt
echo "test$i" > $count_4.txt
((count++))
done


This will mean that you will have files named 1_1.txt, to 300_1.txt






share|improve this answer













There are a couple of ways to do this. Which is most efficient will depend on how your script works. If you can edit your question to contain your script or a snippet at least, I'll edit this to reflect a more accurate answer for your situation.



Here's an example for loop that runs 300 times:



for i in 1..300; do
echo "test$i" > 1.txt
echo "test$i" > 2.txt
echo "test$i" > 3.txt
echo "test$i" > 4.txt
done


That, as it stands, will overwrite 1-4.txt each loop as you mention your script does.



here's a simple solution:



count=1
for i in 1..300; do
echo "test$i" > $count_1.txt
echo "test$i" > $count_2.txt
echo "test$i" > $count_3.txt
echo "test$i" > $count_4.txt
((count++))
done


This will mean that you will have files named 1_1.txt, to 300_1.txt







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 20 at 13:27









RobotJohnnyRobotJohnny

804417




804417












  • Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

    – newbie1
    Feb 21 at 0:13











  • I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

    – RobotJohnny
    Feb 21 at 10:38











  • I see. Thanks for your time.

    – newbie1
    Feb 26 at 6:54

















  • Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

    – newbie1
    Feb 21 at 0:13











  • I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

    – RobotJohnny
    Feb 21 at 10:38











  • I see. Thanks for your time.

    – newbie1
    Feb 26 at 6:54
















Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

– newbie1
Feb 21 at 0:13





Thank you for your answer. My program is written in Fortran and I do not have permission to edit the code. So I wonder that can I use the script to do this job. Best regards.

– newbie1
Feb 21 at 0:13













I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

– RobotJohnny
Feb 21 at 10:38





I'm not sure how you'd expect to achieve this without editing the code to be honest. you could have a script that watches the directory those files are created in constantly, then move them immediately, but that would be a high i/o and very inefficient script for this purpose..

– RobotJohnny
Feb 21 at 10:38













I see. Thanks for your time.

– newbie1
Feb 26 at 6:54





I see. Thanks for your time.

– newbie1
Feb 26 at 6:54

















draft saved

draft discarded
















































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%2f501786%2fhow-to-automatically-change-name-of-a-new-appear-file-in-a-loop-while-running-pr%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

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay