Need Desire output using shell [on hold]2019 Community Moderator ElectionHow to strip multiple spaces to one using sed?Replacing a pattern with another between first and second occurrence of a pattern in fileprinting special characters in awk outputHow can I split a line into two lines if the length is greater than 7 using awk?Find first occurence of a number in each line of a fileHow to Compare two files words by words and it should shows at which line and at which position the differences are presentsearch a string and print the string and it's headerHow to use grep to get the matching part only, without introducing extra newlinesHow to print only 1 filename together with the matching pattern?How to find last occurrence of pattern and print all lines following the last occurance

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Science Fiction story where a man invents a machine that can help him watch history unfold

Simple recursive Sudoku solver

Perfect riffle shuffles

How to check participants in at events?

Organic chemistry Iodoform Reaction

Have I saved too much for retirement so far?

Stereotypical names

Who must act to prevent Brexit on March 29th?

Meta programming: Declare a new struct on the fly

Can somebody explain Brexit in a few child-proof sentences?

For airliners, what prevents wing strikes on landing in bad weather?

Superhero words!

A known event to a history junkie

Resetting two CD4017 counters simultaneously, only one resets

Greatest common substring

Is the next prime number always the next number divisible by the current prime number, except for any numbers previously divisible by primes?

Adding empty element to declared container without declaring type of element

Can I Retrieve Email Addresses from BCC?

Can I rely on these GitHub repository files?

Can a Gentile theist be saved?

The most efficient algorithm to find all possible integer pairs which sum to a given integer

Does "Dominei" mean something?

Can a malicious addon access internet history and such in chrome/firefox?



Need Desire output using shell [on hold]



2019 Community Moderator ElectionHow to strip multiple spaces to one using sed?Replacing a pattern with another between first and second occurrence of a pattern in fileprinting special characters in awk outputHow can I split a line into two lines if the length is greater than 7 using awk?Find first occurence of a number in each line of a fileHow to Compare two files words by words and it should shows at which line and at which position the differences are presentsearch a string and print the string and it's headerHow to use grep to get the matching part only, without introducing extra newlinesHow to print only 1 filename together with the matching pattern?How to find last occurrence of pattern and print all lines following the last occurance










-5















I need to get desired output using a shell script.



Input:



aaabbcaaabbcc 


Desired Output:



a3b2ca3b2c2 


Command should print number of occurrence of each alphabet only when it's greater than 1, i.e aaab should come as a3b.



I tried with below commands and they didn't work for me, as I have to pass characters manually to my command.



echo "aaabbcaaabbcc" | grep -o a 
echo "aaabbcaaabbcc" | uniq -c
echo "aaabbcaaabbcc" | grep -o a | uniq -c


I am unable to find how I can split it character-wise and then check number of occurrences.










share|improve this question















put on hold as unclear what you're asking by Kusalananda, JdeBP, Jeff Schaller, jimmij, Mr Shunz 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • 1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

    – Nasir Riley
    2 days ago







  • 1





    You seem to want to implement some form run-length encoding. What issues are you having with doing this?

    – Kusalananda
    2 days ago











  • There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

    – JdeBP
    2 days ago






  • 2





    Related: rosettacode.org/wiki/Run-length_encoding

    – Kusalananda
    2 days ago






  • 1





    @Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

    – Kusalananda
    13 hours ago
















-5















I need to get desired output using a shell script.



Input:



aaabbcaaabbcc 


Desired Output:



a3b2ca3b2c2 


Command should print number of occurrence of each alphabet only when it's greater than 1, i.e aaab should come as a3b.



I tried with below commands and they didn't work for me, as I have to pass characters manually to my command.



echo "aaabbcaaabbcc" | grep -o a 
echo "aaabbcaaabbcc" | uniq -c
echo "aaabbcaaabbcc" | grep -o a | uniq -c


I am unable to find how I can split it character-wise and then check number of occurrences.










share|improve this question















put on hold as unclear what you're asking by Kusalananda, JdeBP, Jeff Schaller, jimmij, Mr Shunz 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • 1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

    – Nasir Riley
    2 days ago







  • 1





    You seem to want to implement some form run-length encoding. What issues are you having with doing this?

    – Kusalananda
    2 days ago











  • There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

    – JdeBP
    2 days ago






  • 2





    Related: rosettacode.org/wiki/Run-length_encoding

    – Kusalananda
    2 days ago






  • 1





    @Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

    – Kusalananda
    13 hours ago














-5












-5








-5








I need to get desired output using a shell script.



Input:



aaabbcaaabbcc 


Desired Output:



a3b2ca3b2c2 


Command should print number of occurrence of each alphabet only when it's greater than 1, i.e aaab should come as a3b.



I tried with below commands and they didn't work for me, as I have to pass characters manually to my command.



echo "aaabbcaaabbcc" | grep -o a 
echo "aaabbcaaabbcc" | uniq -c
echo "aaabbcaaabbcc" | grep -o a | uniq -c


I am unable to find how I can split it character-wise and then check number of occurrences.










share|improve this question
















I need to get desired output using a shell script.



Input:



aaabbcaaabbcc 


Desired Output:



a3b2ca3b2c2 


Command should print number of occurrence of each alphabet only when it's greater than 1, i.e aaab should come as a3b.



I tried with below commands and they didn't work for me, as I have to pass characters manually to my command.



echo "aaabbcaaabbcc" | grep -o a 
echo "aaabbcaaabbcc" | uniq -c
echo "aaabbcaaabbcc" | grep -o a | uniq -c


I am unable to find how I can split it character-wise and then check number of occurrences.







shell-script text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago









Jeff Schaller

43.9k1161141




43.9k1161141










asked 2 days ago









MachineMachine

335




335




put on hold as unclear what you're asking by Kusalananda, JdeBP, Jeff Schaller, jimmij, Mr Shunz 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









put on hold as unclear what you're asking by Kusalananda, JdeBP, Jeff Schaller, jimmij, Mr Shunz 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

    – Nasir Riley
    2 days ago







  • 1





    You seem to want to implement some form run-length encoding. What issues are you having with doing this?

    – Kusalananda
    2 days ago











  • There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

    – JdeBP
    2 days ago






  • 2





    Related: rosettacode.org/wiki/Run-length_encoding

    – Kusalananda
    2 days ago






  • 1





    @Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

    – Kusalananda
    13 hours ago


















  • 1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

    – Nasir Riley
    2 days ago







  • 1





    You seem to want to implement some form run-length encoding. What issues are you having with doing this?

    – Kusalananda
    2 days ago











  • There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

    – JdeBP
    2 days ago






  • 2





    Related: rosettacode.org/wiki/Run-length_encoding

    – Kusalananda
    2 days ago






  • 1





    @Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

    – Kusalananda
    13 hours ago

















1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

– Nasir Riley
2 days ago






1) Where is the input coming from? Is it the contents of a text file? The output of a command or application? 2) What have you tried to do? If you just want to replace the string in the input with the string in the desired output then you don't need a shell script. Have a look at the sed command.

– Nasir Riley
2 days ago





1




1





You seem to want to implement some form run-length encoding. What issues are you having with doing this?

– Kusalananda
2 days ago





You seem to want to implement some form run-length encoding. What issues are you having with doing this?

– Kusalananda
2 days ago













There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

– JdeBP
2 days ago





There are far too many possible answers with this incomplete and underspecified question, starting with echo a3b2ca3b2c2.

– JdeBP
2 days ago




2




2





Related: rosettacode.org/wiki/Run-length_encoding

– Kusalananda
2 days ago





Related: rosettacode.org/wiki/Run-length_encoding

– Kusalananda
2 days ago




1




1





@Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

– Kusalananda
13 hours ago






@Machine Run-length encoding (RLE) is a well known and simple way of compressing highly redundant data. If you have a particular issue with the awk variant on the Rosetta page that I linked to, then you may want to ask another question about it. Pure programming questions relating to the implementation of specific algorithms would arguably be more suitable on StackOverflow though.

– Kusalananda
13 hours ago











1 Answer
1






active

oldest

votes


















2














str="aaabbcaaabbcc"

echo $str | fold -w1 | uniq -c |
while read count char; do
if [ $count -gt 1 ]; then
printf "$char$count"
else
printf "$char"
fi
done



a3b2ca3b2c2







share|improve this answer




















  • 1





    There seems to be a special case for $count -eq 1

    – nohillside
    2 days ago






  • 1





    Indeed. Fixed for that case.

    – Fedor Dikarev
    2 days ago











  • This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

    – Kusalananda
    2 days ago












  • @ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

    – Machine
    13 hours ago

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














str="aaabbcaaabbcc"

echo $str | fold -w1 | uniq -c |
while read count char; do
if [ $count -gt 1 ]; then
printf "$char$count"
else
printf "$char"
fi
done



a3b2ca3b2c2







share|improve this answer




















  • 1





    There seems to be a special case for $count -eq 1

    – nohillside
    2 days ago






  • 1





    Indeed. Fixed for that case.

    – Fedor Dikarev
    2 days ago











  • This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

    – Kusalananda
    2 days ago












  • @ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

    – Machine
    13 hours ago















2














str="aaabbcaaabbcc"

echo $str | fold -w1 | uniq -c |
while read count char; do
if [ $count -gt 1 ]; then
printf "$char$count"
else
printf "$char"
fi
done



a3b2ca3b2c2







share|improve this answer




















  • 1





    There seems to be a special case for $count -eq 1

    – nohillside
    2 days ago






  • 1





    Indeed. Fixed for that case.

    – Fedor Dikarev
    2 days ago











  • This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

    – Kusalananda
    2 days ago












  • @ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

    – Machine
    13 hours ago













2












2








2







str="aaabbcaaabbcc"

echo $str | fold -w1 | uniq -c |
while read count char; do
if [ $count -gt 1 ]; then
printf "$char$count"
else
printf "$char"
fi
done



a3b2ca3b2c2







share|improve this answer















str="aaabbcaaabbcc"

echo $str | fold -w1 | uniq -c |
while read count char; do
if [ $count -gt 1 ]; then
printf "$char$count"
else
printf "$char"
fi
done



a3b2ca3b2c2








share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Fedor DikarevFedor Dikarev

1,103310




1,103310







  • 1





    There seems to be a special case for $count -eq 1

    – nohillside
    2 days ago






  • 1





    Indeed. Fixed for that case.

    – Fedor Dikarev
    2 days ago











  • This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

    – Kusalananda
    2 days ago












  • @ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

    – Machine
    13 hours ago












  • 1





    There seems to be a special case for $count -eq 1

    – nohillside
    2 days ago






  • 1





    Indeed. Fixed for that case.

    – Fedor Dikarev
    2 days ago











  • This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

    – Kusalananda
    2 days ago












  • @ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

    – Machine
    13 hours ago







1




1





There seems to be a special case for $count -eq 1

– nohillside
2 days ago





There seems to be a special case for $count -eq 1

– nohillside
2 days ago




1




1





Indeed. Fixed for that case.

– Fedor Dikarev
2 days ago





Indeed. Fixed for that case.

– Fedor Dikarev
2 days ago













This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

– Kusalananda
2 days ago






This would unfortunately fail if the string contained backslashes or percentage signs, or filename globbing patterns, or started with a dash, or if IFS was set to a set of digits or letters.

– Kusalananda
2 days ago














@ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

– Machine
13 hours ago





@ Fedor Dikarev , I never knew about fold which can split a word vertically in char form. Thanks for this

– Machine
13 hours ago



-shell-script, text-processing

Popular posts from this blog

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant