Add 100 to decimals in Multiple TXT files

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.
sample
"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]
text-processing json jq
 |Â
show 2 more comments
up vote
0
down vote
favorite
I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.
sample
"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]
text-processing json jq
3
post a testable file's content (we need to see whether"moves":30,is a part of the line or stands as a separate line)
â RomanPerekhrest
May 8 at 7:12
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
1
A full example would still be good.
â Kusalananda
May 8 at 7:24
2
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, useon the formatting bar to mark it as code.) A question should ideally be complete in itself.
â roaima
May 8 at 7:36
1
Also specify whether there could be multiple entries"moves":<number>,on the same line
â RomanPerekhrest
May 8 at 7:39
 |Â
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.
sample
"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]
text-processing json jq
I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.
sample
"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]
text-processing json jq
edited May 9 at 9:39
Jeff Schaller
31.1k846105
31.1k846105
asked May 8 at 7:10
PJ547
91
91
3
post a testable file's content (we need to see whether"moves":30,is a part of the line or stands as a separate line)
â RomanPerekhrest
May 8 at 7:12
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
1
A full example would still be good.
â Kusalananda
May 8 at 7:24
2
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, useon the formatting bar to mark it as code.) A question should ideally be complete in itself.
â roaima
May 8 at 7:36
1
Also specify whether there could be multiple entries"moves":<number>,on the same line
â RomanPerekhrest
May 8 at 7:39
 |Â
show 2 more comments
3
post a testable file's content (we need to see whether"moves":30,is a part of the line or stands as a separate line)
â RomanPerekhrest
May 8 at 7:12
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
1
A full example would still be good.
â Kusalananda
May 8 at 7:24
2
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, useon the formatting bar to mark it as code.) A question should ideally be complete in itself.
â roaima
May 8 at 7:36
1
Also specify whether there could be multiple entries"moves":<number>,on the same line
â RomanPerekhrest
May 8 at 7:39
3
3
post a testable file's content (we need to see whether
"moves":30, is a part of the line or stands as a separate line)â RomanPerekhrest
May 8 at 7:12
post a testable file's content (we need to see whether
"moves":30, is a part of the line or stands as a separate line)â RomanPerekhrest
May 8 at 7:12
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
1
1
A full example would still be good.
â Kusalananda
May 8 at 7:24
A full example would still be good.
â Kusalananda
May 8 at 7:24
2
2
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use
on the formatting bar to mark it as code.) A question should ideally be complete in itself.â roaima
May 8 at 7:36
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use
on the formatting bar to mark it as code.) A question should ideally be complete in itself.â roaima
May 8 at 7:36
1
1
Also specify whether there could be multiple entries
"moves":<number>, on the same lineâ RomanPerekhrest
May 8 at 7:39
Also specify whether there could be multiple entries
"moves":<number>, on the same lineâ RomanPerekhrest
May 8 at 7:39
 |Â
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
5
down vote
If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.
Use a proper JSON tools like jq as this would be the right way:
for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
add a comment |Â
up vote
1
down vote
On a GNU or FreeBSD system, you could try something like:
grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'
greprecursivelylists the files in the current directory (.) that contain"moveLimit":followed by a decimal digit (null-delimited forxargs -0)xargs -r0passes that list of files toperlperledits the filesin-place and replaces sequences of digits (d+that follow"moveLimit":with the same number ($&) plus 100.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.
Use a proper JSON tools like jq as this would be the right way:
for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
add a comment |Â
up vote
5
down vote
If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.
Use a proper JSON tools like jq as this would be the right way:
for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
add a comment |Â
up vote
5
down vote
up vote
5
down vote
If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.
Use a proper JSON tools like jq as this would be the right way:
for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done
If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.
Use a proper JSON tools like jq as this would be the right way:
for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done
answered May 8 at 8:06
RomanPerekhrest
22.4k12144
22.4k12144
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
add a comment |Â
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
This worked ! Thanks a lot.
â PJ547
May 8 at 8:26
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
@PJ547, you're welcome
â RomanPerekhrest
May 8 at 9:06
2
2
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
@PJ547 Good! If this solves your issue, please consider accepting the answer.
â Kusalananda
May 8 at 10:12
add a comment |Â
up vote
1
down vote
On a GNU or FreeBSD system, you could try something like:
grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'
greprecursivelylists the files in the current directory (.) that contain"moveLimit":followed by a decimal digit (null-delimited forxargs -0)xargs -r0passes that list of files toperlperledits the filesin-place and replaces sequences of digits (d+that follow"moveLimit":with the same number ($&) plus 100.
add a comment |Â
up vote
1
down vote
On a GNU or FreeBSD system, you could try something like:
grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'
greprecursivelylists the files in the current directory (.) that contain"moveLimit":followed by a decimal digit (null-delimited forxargs -0)xargs -r0passes that list of files toperlperledits the filesin-place and replaces sequences of digits (d+that follow"moveLimit":with the same number ($&) plus 100.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
On a GNU or FreeBSD system, you could try something like:
grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'
greprecursivelylists the files in the current directory (.) that contain"moveLimit":followed by a decimal digit (null-delimited forxargs -0)xargs -r0passes that list of files toperlperledits the filesin-place and replaces sequences of digits (d+that follow"moveLimit":with the same number ($&) plus 100.
On a GNU or FreeBSD system, you could try something like:
grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'
greprecursivelylists the files in the current directory (.) that contain"moveLimit":followed by a decimal digit (null-delimited forxargs -0)xargs -r0passes that list of files toperlperledits the filesin-place and replaces sequences of digits (d+that follow"moveLimit":with the same number ($&) plus 100.
edited May 8 at 8:57
answered May 8 at 8:05
Stéphane Chazelas
279k53514845
279k53514845
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442475%2fadd-100-to-decimals-in-multiple-txt-files%23new-answer', 'question_page');
);
Post as a guest
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
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
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
3
post a testable file's content (we need to see whether
"moves":30,is a part of the line or stands as a separate line)â RomanPerekhrest
May 8 at 7:12
It's in a single line, and doesn't stand therefore as a separate line.
â PJ547
May 8 at 7:19
1
A full example would still be good.
â Kusalananda
May 8 at 7:24
2
Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use
on the formatting bar to mark it as code.) A question should ideally be complete in itself.â roaima
May 8 at 7:36
1
Also specify whether there could be multiple entries
"moves":<number>,on the same lineâ RomanPerekhrest
May 8 at 7:39