0

I'm trying to make this program work and I can't, The script i want must should calculate count of char use in string example : string=good result=g1o2d1 is there any way to write script that calculate exactly count of string like my example or not ?

 #!/bin/bash
    string=ssstttrrrriiiinnnnngg
    z=$( for((i=0;i<${#string};i++)) do; echo ${string:i:1}; done | uniq -c )
    echo $z

my result :

s 3 t 3 r 4 i 4 n 5 g 2

but for analysis some document i want script to calculate char some like firstchar1=$( bash script ) ...... i need that value for use another script please advise me regards

1 Answer 1

1
$ echo "abaaacdefg" | grep -o .
a
b
a
a
a
c
d
e
f
g

$ echo "abaaacdefg" | grep -o .| sort
a
a
a
a
b
c
d
e
f
g

$  echo "abaaacdefg" | grep -o .| sort |  uniq -c 
      4 a
      1 b
      1 c
      1 d
      1 e
      1 f
      1 g


$ echo "abaaacdefg" | grep -o .| sort |  uniq -c | awk '{printf $2$1}'
a4b1c1d1e1f1g1

See Bash: Split string into character array and counting duplicates in a sorted sequence using command line tools

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.