How to automatically change name of a new appear file in a loop while running program which has many loop
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
shell-script
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
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%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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
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%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
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
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