Completing the count of charcters in every line with dots
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I would like to know how to count the characters in every line in a text, then subtracting this number from a threshold represents the maximum number of characters allowed per line, after then I would like to fill the gaps between the maximum number of characters and the count of characters with dots. For example:
Unix was
originally meant
to be a
co
nvenient p
latform for progra
mmers developing software to
be run on it and on other
systems, rather than for non-
programmers.
[7][8] The system grew larger
as the operating system star
ted spreading in a
cademic circ
les, as users add
ed their own tools to th
e system and shared them wi
th colleagues.
The maximum number of characters over all the lines is /31/ in line#11. I would like the count of characters in every line to be /31/ by filling the empty spaces with dots, like this:
Unix was , .....................
originally meant , .............
to be a , ......................
co, ............................
nvenient p, ....................
latform for progra, ............
mmers developing software to, ..
be run on it and on other , ....
systems, rather than for non-,..
programmers., ..................
[7][8] The system grew larger,..
as the operating system star, ..
ted spreading in a, ............
cademic circ, ..................
les, as users add, .............
ed their own tools to th, ......
e system and shared them wi, ...
th colleagues., ................
How can I do that in bash
?
bash
add a comment |Â
up vote
1
down vote
favorite
I would like to know how to count the characters in every line in a text, then subtracting this number from a threshold represents the maximum number of characters allowed per line, after then I would like to fill the gaps between the maximum number of characters and the count of characters with dots. For example:
Unix was
originally meant
to be a
co
nvenient p
latform for progra
mmers developing software to
be run on it and on other
systems, rather than for non-
programmers.
[7][8] The system grew larger
as the operating system star
ted spreading in a
cademic circ
les, as users add
ed their own tools to th
e system and shared them wi
th colleagues.
The maximum number of characters over all the lines is /31/ in line#11. I would like the count of characters in every line to be /31/ by filling the empty spaces with dots, like this:
Unix was , .....................
originally meant , .............
to be a , ......................
co, ............................
nvenient p, ....................
latform for progra, ............
mmers developing software to, ..
be run on it and on other , ....
systems, rather than for non-,..
programmers., ..................
[7][8] The system grew larger,..
as the operating system star, ..
ted spreading in a, ............
cademic circ, ..................
les, as users add, .............
ed their own tools to th, ......
e system and shared them wi, ...
th colleagues., ................
How can I do that in bash
?
bash
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to know how to count the characters in every line in a text, then subtracting this number from a threshold represents the maximum number of characters allowed per line, after then I would like to fill the gaps between the maximum number of characters and the count of characters with dots. For example:
Unix was
originally meant
to be a
co
nvenient p
latform for progra
mmers developing software to
be run on it and on other
systems, rather than for non-
programmers.
[7][8] The system grew larger
as the operating system star
ted spreading in a
cademic circ
les, as users add
ed their own tools to th
e system and shared them wi
th colleagues.
The maximum number of characters over all the lines is /31/ in line#11. I would like the count of characters in every line to be /31/ by filling the empty spaces with dots, like this:
Unix was , .....................
originally meant , .............
to be a , ......................
co, ............................
nvenient p, ....................
latform for progra, ............
mmers developing software to, ..
be run on it and on other , ....
systems, rather than for non-,..
programmers., ..................
[7][8] The system grew larger,..
as the operating system star, ..
ted spreading in a, ............
cademic circ, ..................
les, as users add, .............
ed their own tools to th, ......
e system and shared them wi, ...
th colleagues., ................
How can I do that in bash
?
bash
I would like to know how to count the characters in every line in a text, then subtracting this number from a threshold represents the maximum number of characters allowed per line, after then I would like to fill the gaps between the maximum number of characters and the count of characters with dots. For example:
Unix was
originally meant
to be a
co
nvenient p
latform for progra
mmers developing software to
be run on it and on other
systems, rather than for non-
programmers.
[7][8] The system grew larger
as the operating system star
ted spreading in a
cademic circ
les, as users add
ed their own tools to th
e system and shared them wi
th colleagues.
The maximum number of characters over all the lines is /31/ in line#11. I would like the count of characters in every line to be /31/ by filling the empty spaces with dots, like this:
Unix was , .....................
originally meant , .............
to be a , ......................
co, ............................
nvenient p, ....................
latform for progra, ............
mmers developing software to, ..
be run on it and on other , ....
systems, rather than for non-,..
programmers., ..................
[7][8] The system grew larger,..
as the operating system star, ..
ted spreading in a, ............
cademic circ, ..................
les, as users add, .............
ed their own tools to th, ......
e system and shared them wi, ...
th colleagues., ................
How can I do that in bash
?
bash
bash
edited 5 mins ago
Goro
8,79564384
8,79564384
asked 1 hour ago
Shervan
34811
34811
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Try this code:
#!/bin/bash
# This loop is to count the number of bytes per line, then it will find the max number of bytes over all the lines
max=$(cat datafile| while IFS=" " read line; do echo "$line" | wc -c; done | sort -k 1.1n | tail -n1)
cat datafile| while IFS=" " read line; do
# Count of bytes in every line
n=$(echo "$line" | wc -c)
# bytes difference in every line
diff=$(echo $(($max-$n)))
# complete the number of bytes per line to the max number of bytes over all the lines.
dash=$(printf %"$diff"s | tr " " ".")
# print results
echo $line,$dash
done
output:
Unix was,.....................
originally meant,.............
to be a,......................
co,...........................
nvenient p,...................
latform for progra,...........
mmers developing software to,.
be run on it and on other,....
systems, rather than for non-,
programmers.,.................
[7][8] The system grew larger,
as the operating system star,.
ted spreading in a,...........
cademic circ,.................
les, as users add,............
ed their own tools to th,.....
e system and shared them wi,..
th colleagues.,...............
add a comment |Â
up vote
1
down vote
For text processing tasks, I'd suggest using something like Awk or Perl in place of bash
e.g.
perl -lnE '
push @a, $_; $max = length $_ > $max ? length $_ : $max
} tail -n1)
cat datafileimprove this answer
add a comment Â
up vote
1
down vote
up vote
1
down vote
For text processing tasks, I'd suggest using something like Awk or Perl in place of bash
e.g.
perl -lnE '
push @a, $_; $max = length $_ > $max ? length $_ : $max
improve this answer
For text processing tasks, I'd suggest using something like Awk or Perl in place of bash
e.g.
perl -lnE '
push @a, $_; $max = length $_ > $max ? length $_ : $max
{
foreach $x (@a) say $x, ", ", "."x($max - length $x)
' file
Unix was , ....................
originally meant , ............
to be a , .....................
co, ...........................
nvenient p, ...................
latform for progra, ...........
mmers developing software to, .
be run on it and on other , ..
systems, rather than for non-,
programmers., .................
[7][8] The system grew larger,
as the operating system star,
ted spreading in a, ...........
cademic circ, .................
les, as users add, ............
ed their own tools to th, .....
e system and shared them wi, ..
th colleagues., ...............
answered 56 mins ago
steeldriver
33k34982
33k34982
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%2f475198%2fcompleting-the-count-of-charcters-in-every-line-with-dots%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