Moving zero padded files based on sequence
I am trying to move repetitive generation of files in sequence like [00000.txt ... 99999.txt] and maintaing current date logs
I tried with below script which is working for single digit numbers such as 0..9 but not for 00000..99999
Kindly help me to achieve this.
Thanks in advance.
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/
declare -i y=0
y=cat counter.txt
(( y++ ))
echo "value of y is $y"
while [ $y -lt 9 ];
do
while true; do
if [ $y -eq 8 ]
then
cp $y.txt temp/operator1/
y=0
echo "maximum limit has reached to 8 resetting counter to 0" >> log_$(date +%Y%m%d).txt
fi
if [ -f $y.txt ]
then
cp $y.txt temp/operator1/
echo $y > counter.txt
(( y++ ))
echo "$y.txt has been copied to new folder" >> log_$(date +%Y%m%d).txt
break
else
echo "waiting for $y.txt" >> log_$(date +%Y%m%d).txt
sleep 5
fi
done
done
bash unix shell shell-script bash-scripting
New contributor
add a comment |
I am trying to move repetitive generation of files in sequence like [00000.txt ... 99999.txt] and maintaing current date logs
I tried with below script which is working for single digit numbers such as 0..9 but not for 00000..99999
Kindly help me to achieve this.
Thanks in advance.
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/
declare -i y=0
y=cat counter.txt
(( y++ ))
echo "value of y is $y"
while [ $y -lt 9 ];
do
while true; do
if [ $y -eq 8 ]
then
cp $y.txt temp/operator1/
y=0
echo "maximum limit has reached to 8 resetting counter to 0" >> log_$(date +%Y%m%d).txt
fi
if [ -f $y.txt ]
then
cp $y.txt temp/operator1/
echo $y > counter.txt
(( y++ ))
echo "$y.txt has been copied to new folder" >> log_$(date +%Y%m%d).txt
break
else
echo "waiting for $y.txt" >> log_$(date +%Y%m%d).txt
sleep 5
fi
done
done
bash unix shell shell-script bash-scripting
New contributor
1
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
1
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role ofcounter.txt
?).
– Scott
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago
add a comment |
I am trying to move repetitive generation of files in sequence like [00000.txt ... 99999.txt] and maintaing current date logs
I tried with below script which is working for single digit numbers such as 0..9 but not for 00000..99999
Kindly help me to achieve this.
Thanks in advance.
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/
declare -i y=0
y=cat counter.txt
(( y++ ))
echo "value of y is $y"
while [ $y -lt 9 ];
do
while true; do
if [ $y -eq 8 ]
then
cp $y.txt temp/operator1/
y=0
echo "maximum limit has reached to 8 resetting counter to 0" >> log_$(date +%Y%m%d).txt
fi
if [ -f $y.txt ]
then
cp $y.txt temp/operator1/
echo $y > counter.txt
(( y++ ))
echo "$y.txt has been copied to new folder" >> log_$(date +%Y%m%d).txt
break
else
echo "waiting for $y.txt" >> log_$(date +%Y%m%d).txt
sleep 5
fi
done
done
bash unix shell shell-script bash-scripting
New contributor
I am trying to move repetitive generation of files in sequence like [00000.txt ... 99999.txt] and maintaing current date logs
I tried with below script which is working for single digit numbers such as 0..9 but not for 00000..99999
Kindly help me to achieve this.
Thanks in advance.
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/
declare -i y=0
y=cat counter.txt
(( y++ ))
echo "value of y is $y"
while [ $y -lt 9 ];
do
while true; do
if [ $y -eq 8 ]
then
cp $y.txt temp/operator1/
y=0
echo "maximum limit has reached to 8 resetting counter to 0" >> log_$(date +%Y%m%d).txt
fi
if [ -f $y.txt ]
then
cp $y.txt temp/operator1/
echo $y > counter.txt
(( y++ ))
echo "$y.txt has been copied to new folder" >> log_$(date +%Y%m%d).txt
break
else
echo "waiting for $y.txt" >> log_$(date +%Y%m%d).txt
sleep 5
fi
done
done
bash unix shell shell-script bash-scripting
bash unix shell shell-script bash-scripting
New contributor
New contributor
edited 7 hours ago
Hari B
New contributor
asked Jan 6 at 10:33
Hari BHari B
11
11
New contributor
New contributor
1
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
1
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role ofcounter.txt
?).
– Scott
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago
add a comment |
1
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
1
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role ofcounter.txt
?).
– Scott
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago
1
1
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
1
1
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role of
counter.txt
?).– Scott
2 days ago
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role of
counter.txt
?).– Scott
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
Hari B is a new contributor. Be nice, and check out our Code of Conduct.
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%2fsuperuser.com%2fquestions%2f1391117%2fmoving-zero-padded-files-based-on-sequence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Hari B is a new contributor. Be nice, and check out our Code of Conduct.
Hari B is a new contributor. Be nice, and check out our Code of Conduct.
Hari B is a new contributor. Be nice, and check out our Code of Conduct.
Hari B is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Super User!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fsuperuser.com%2fquestions%2f1391117%2fmoving-zero-padded-files-based-on-sequence%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
1
Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill♦
Jan 6 at 10:42
1
A program/script that’s “missing some logic” is like a car with a flat tire — it doesn’t work correctly, but it works. Your script is like a car with no wheels and no fuel. Please try to get it to a point where it works poorly — a simple search will find many resources to help you. (There is one major error right in the middle that you should be able to spot easily.) Also, please try to describe more clearly what your requirements are (what does “This sequence will repeat again” mean?) and how the script is supposed to be satisfying them (what is the role of
counter.txt
?).– Scott
2 days ago
Hi Scott, I used Counter.txt to save the last moved file. My requirement is like I will receive the files such as ABCD00000.txt....ABCD99999.txt. once the complete set is received, again the same set will receive. before that I need to move the files to destination and in sequence.
– Hari B
2 days ago