How to use awk to find and replace with calculation? [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
This question already has an answer here:
Bash script Multiply only numbers from a text file?
4 answers
I have several CSS files under a folder contains 0.2rem
or 0.5rem 0.6rem
, now I want them to be all divided by 2, become 0.1rem
and 0.25rem, 0.3rem
. How can I use awk
or sed
or gawk
to accomplish this?
I tried the following command but have no success:
find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'
awk
marked as duplicate by ñÃÂsýù÷, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
5
down vote
favorite
This question already has an answer here:
Bash script Multiply only numbers from a text file?
4 answers
I have several CSS files under a folder contains 0.2rem
or 0.5rem 0.6rem
, now I want them to be all divided by 2, become 0.1rem
and 0.25rem, 0.3rem
. How can I use awk
or sed
or gawk
to accomplish this?
I tried the following command but have no success:
find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'
awk
marked as duplicate by ñÃÂsýù÷, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
This question already has an answer here:
Bash script Multiply only numbers from a text file?
4 answers
I have several CSS files under a folder contains 0.2rem
or 0.5rem 0.6rem
, now I want them to be all divided by 2, become 0.1rem
and 0.25rem, 0.3rem
. How can I use awk
or sed
or gawk
to accomplish this?
I tried the following command but have no success:
find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'
awk
This question already has an answer here:
Bash script Multiply only numbers from a text file?
4 answers
I have several CSS files under a folder contains 0.2rem
or 0.5rem 0.6rem
, now I want them to be all divided by 2, become 0.1rem
and 0.25rem, 0.3rem
. How can I use awk
or sed
or gawk
to accomplish this?
I tried the following command but have no success:
find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'
This question already has an answer here:
Bash script Multiply only numbers from a text file?
4 answers
awk
edited Mar 14 at 10:07
David Foerster
915616
915616
asked Mar 14 at 6:48
Zhang Buzz
1284
1284
marked as duplicate by ñÃÂsýù÷, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ñÃÂsýù÷, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
5
down vote
accepted
find
+ GNU awk
solution:
find . -type f -name "*.css" -exec gawk -i inplace
' for (i=1; i<=NF; i++)
if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
1' ;
Thank you! I tried with some change:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the;
is striped on every line. For example,padding-bottom: 2rem;
becomespadding-bottom: 1rem
after change. Do you know why?
â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
add a comment |Â
up vote
7
down vote
Not sure about sed/gawk
, but here's one with perl
$ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
0.1rem or 0.25rem 0.3rem
d+(.d+)?
match digits with optional fractional part(?=rem)
to ensure the number is followed byrem
$&*0.5
multiply the number by0.5
- thee
modifier allows to use Perl code instead of string in replacement section
Applying to files:
find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +
See also: Why is looping over find's output bad practice?
That link is about looping over the output of find (e.g.for i in $(findâ¦)
), not using find's internal loop (-exec
or-execdir
).
â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
add a comment |Â
up vote
4
down vote
With gawk
, you could use RS
that is treated as a regexp there and the fact that there, RT
contains what was matched by RS
. So:
find . -name '*.css' -type f -exec
gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +
add a comment |Â
up vote
1
down vote
gawk -i inplace '
for(i = 1; i <= NF; i++)
if($i ~ /[0-9]+(.[0-9]+)?rem/)
$i = $i / 2 "rem"
print
' file_*
The 3 files content before the program execution
The tail -n +1 -- file_*
command shows the multiple files content at once.
$ tail -n +1 -- file_*
==> file_1 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
==> file_2 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
==> file_3 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
The 3 files content after the program execution
$ tail -n +1 -- file_*
==> file_1 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
==> file_2 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
==> file_3 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
find
+ GNU awk
solution:
find . -type f -name "*.css" -exec gawk -i inplace
' for (i=1; i<=NF; i++)
if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
1' ;
Thank you! I tried with some change:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the;
is striped on every line. For example,padding-bottom: 2rem;
becomespadding-bottom: 1rem
after change. Do you know why?
â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
add a comment |Â
up vote
5
down vote
accepted
find
+ GNU awk
solution:
find . -type f -name "*.css" -exec gawk -i inplace
' for (i=1; i<=NF; i++)
if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
1' ;
Thank you! I tried with some change:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the;
is striped on every line. For example,padding-bottom: 2rem;
becomespadding-bottom: 1rem
after change. Do you know why?
â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
find
+ GNU awk
solution:
find . -type f -name "*.css" -exec gawk -i inplace
' for (i=1; i<=NF; i++)
if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
1' ;
find
+ GNU awk
solution:
find . -type f -name "*.css" -exec gawk -i inplace
' for (i=1; i<=NF; i++)
if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
1' ;
edited Mar 14 at 7:36
answered Mar 14 at 7:00
RomanPerekhrest
22.4k12144
22.4k12144
Thank you! I tried with some change:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the;
is striped on every line. For example,padding-bottom: 2rem;
becomespadding-bottom: 1rem
after change. Do you know why?
â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
add a comment |Â
Thank you! I tried with some change:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the;
is striped on every line. For example,padding-bottom: 2rem;
becomespadding-bottom: 1rem
after change. Do you know why?
â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
Thank you! I tried with some change:
find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the ;
is striped on every line. For example, padding-bottom: 2rem;
becomes padding-bottom: 1rem
after change. Do you know why?â Zhang Buzz
Mar 14 at 7:28
Thank you! I tried with some change:
find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1'
, everything works fine, just the ;
is striped on every line. For example, padding-bottom: 2rem;
becomes padding-bottom: 1rem
after change. Do you know why?â Zhang Buzz
Mar 14 at 7:28
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
@ZhangBuzz, you did not mention that in your question. Anyway, see my update
â RomanPerekhrest
Mar 14 at 7:37
I got it! The final command I use is as this:
find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
I got it! The final command I use is as this:
find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
â Zhang Buzz
Mar 14 at 7:58
add a comment |Â
up vote
7
down vote
Not sure about sed/gawk
, but here's one with perl
$ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
0.1rem or 0.25rem 0.3rem
d+(.d+)?
match digits with optional fractional part(?=rem)
to ensure the number is followed byrem
$&*0.5
multiply the number by0.5
- thee
modifier allows to use Perl code instead of string in replacement section
Applying to files:
find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +
See also: Why is looping over find's output bad practice?
That link is about looping over the output of find (e.g.for i in $(findâ¦)
), not using find's internal loop (-exec
or-execdir
).
â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
add a comment |Â
up vote
7
down vote
Not sure about sed/gawk
, but here's one with perl
$ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
0.1rem or 0.25rem 0.3rem
d+(.d+)?
match digits with optional fractional part(?=rem)
to ensure the number is followed byrem
$&*0.5
multiply the number by0.5
- thee
modifier allows to use Perl code instead of string in replacement section
Applying to files:
find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +
See also: Why is looping over find's output bad practice?
That link is about looping over the output of find (e.g.for i in $(findâ¦)
), not using find's internal loop (-exec
or-execdir
).
â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Not sure about sed/gawk
, but here's one with perl
$ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
0.1rem or 0.25rem 0.3rem
d+(.d+)?
match digits with optional fractional part(?=rem)
to ensure the number is followed byrem
$&*0.5
multiply the number by0.5
- thee
modifier allows to use Perl code instead of string in replacement section
Applying to files:
find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +
See also: Why is looping over find's output bad practice?
Not sure about sed/gawk
, but here's one with perl
$ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
0.1rem or 0.25rem 0.3rem
d+(.d+)?
match digits with optional fractional part(?=rem)
to ensure the number is followed byrem
$&*0.5
multiply the number by0.5
- thee
modifier allows to use Perl code instead of string in replacement section
Applying to files:
find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +
See also: Why is looping over find's output bad practice?
answered Mar 14 at 6:58
Sundeep
6,9511826
6,9511826
That link is about looping over the output of find (e.g.for i in $(findâ¦)
), not using find's internal loop (-exec
or-execdir
).
â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
add a comment |Â
That link is about looping over the output of find (e.g.for i in $(findâ¦)
), not using find's internal loop (-exec
or-execdir
).
â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
That link is about looping over the output of find (e.g.
for i in $(findâ¦)
), not using find's internal loop (-exec
or -execdir
).â Sparhawk
Mar 14 at 22:13
That link is about looping over the output of find (e.g.
for i in $(findâ¦)
), not using find's internal loop (-exec
or -execdir
).â Sparhawk
Mar 14 at 22:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...
find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
@Sparhawk but the answers cover that aspect... and has a quote that I like very much...
find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
â Sundeep
Mar 15 at 3:13
1
1
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
â Sparhawk
Mar 15 at 3:17
add a comment |Â
up vote
4
down vote
With gawk
, you could use RS
that is treated as a regexp there and the fact that there, RT
contains what was matched by RS
. So:
find . -name '*.css' -type f -exec
gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +
add a comment |Â
up vote
4
down vote
With gawk
, you could use RS
that is treated as a regexp there and the fact that there, RT
contains what was matched by RS
. So:
find . -name '*.css' -type f -exec
gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +
add a comment |Â
up vote
4
down vote
up vote
4
down vote
With gawk
, you could use RS
that is treated as a regexp there and the fact that there, RT
contains what was matched by RS
. So:
find . -name '*.css' -type f -exec
gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +
With gawk
, you could use RS
that is treated as a regexp there and the fact that there, RT
contains what was matched by RS
. So:
find . -name '*.css' -type f -exec
gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +
edited Mar 22 at 14:11
MiniMax
2,681718
2,681718
answered Mar 14 at 22:09
Stéphane Chazelas
280k53515847
280k53515847
add a comment |Â
add a comment |Â
up vote
1
down vote
gawk -i inplace '
for(i = 1; i <= NF; i++)
if($i ~ /[0-9]+(.[0-9]+)?rem/)
$i = $i / 2 "rem"
print
' file_*
The 3 files content before the program execution
The tail -n +1 -- file_*
command shows the multiple files content at once.
$ tail -n +1 -- file_*
==> file_1 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
==> file_2 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
==> file_3 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
The 3 files content after the program execution
$ tail -n +1 -- file_*
==> file_1 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
==> file_2 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
==> file_3 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
add a comment |Â
up vote
1
down vote
gawk -i inplace '
for(i = 1; i <= NF; i++)
if($i ~ /[0-9]+(.[0-9]+)?rem/)
$i = $i / 2 "rem"
print
' file_*
The 3 files content before the program execution
The tail -n +1 -- file_*
command shows the multiple files content at once.
$ tail -n +1 -- file_*
==> file_1 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
==> file_2 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
==> file_3 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
The 3 files content after the program execution
$ tail -n +1 -- file_*
==> file_1 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
==> file_2 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
==> file_3 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
gawk -i inplace '
for(i = 1; i <= NF; i++)
if($i ~ /[0-9]+(.[0-9]+)?rem/)
$i = $i / 2 "rem"
print
' file_*
The 3 files content before the program execution
The tail -n +1 -- file_*
command shows the multiple files content at once.
$ tail -n +1 -- file_*
==> file_1 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
==> file_2 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
==> file_3 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
The 3 files content after the program execution
$ tail -n +1 -- file_*
==> file_1 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
==> file_2 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
==> file_3 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
gawk -i inplace '
for(i = 1; i <= NF; i++)
if($i ~ /[0-9]+(.[0-9]+)?rem/)
$i = $i / 2 "rem"
print
' file_*
The 3 files content before the program execution
The tail -n +1 -- file_*
command shows the multiple files content at once.
$ tail -n +1 -- file_*
==> file_1 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
==> file_2 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
0.2rem lorem ipsum 0.5rem
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
==> file_3 <==
0.2rem lorem ipsum 0.5rem
Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
The 3 files content after the program execution
$ tail -n +1 -- file_*
==> file_1 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
==> file_2 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
0.1rem lorem ipsum 0.25rem
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
==> file_3 <==
0.1rem lorem ipsum 0.25rem
Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
edited Mar 14 at 21:08
answered Mar 14 at 21:03
MiniMax
2,681718
2,681718
add a comment |Â
add a comment |Â