Haskell: Exception: stack overflow - list

I tried to run this code, but it failed with Exception: stack overflow. I tried to increase stack size to its maximum limit, but it didn't help
I only understand that this code uses peano arithmetics, and functions represent some basic logical and arithmetical functions
Need output from it
plz help me
import Control.Arrow (Arrow (first))
import Data.Char (chr)
main :: IO ()
main =
putStrLn answer
where
answer = zipWith foo bar numbers
foo = curry $ chr . uncurry (-) . first ((`mod` 1021) . e)
bar = c1 : c2 : zipWith f bar (tail bar)
f :: Eq a => [a] -> [a] -> [a]
f x y
| d1 `c` a x y = sb x y
| a x y `c` d2 = a x y
| otherwise = f x $ m x y
z :: [a]
z = []
s :: [()] -> [()]
s x = () : x
a :: Eq a => [a] -> [a] -> [a]
a x y | x == z = y
a (x : xs) y = a xs (x : y)
sb :: Eq a => [b] -> [a] -> [b]
sb x y | y == z = x
sb (_ : xs) (_ : ys) = sb xs ys
m :: (Eq a, Eq b) => [b] -> [a] -> [b]
m x y | y == z = z
m x (y : ys) = a x $ m x ys
c :: (Eq a, Eq b) => [b] -> [a] -> Bool
c _ y | y == z = True
c x _ | x == z = False
c (_ : xs) (y : ys) = c xs ys
e :: (Eq a, Num p) => [a] -> p
e x | x == z = 0
e (_ : xs) = (1 +) $ e xs
numbers = [153, 586, 819, 461, 354, 843, 263, 215, 564, 884, 548, 511, 139, 814, -16, 853, -73, 886, 921, 870, 926, 886, 784, 763, 589, 364, 20, 502, 650, 237, -49, 288, 373, 774, 203, 73, 378, 549, 4, 657, 777, 592, 396, 89, 543, 696, 322, 144, 562, 761, 304, 144, 546, 736, 307, 32, 436, 572, -4, 618, 715, 462, 245, 762, -2, 856, 965, 833, 734]
c1 = s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s z
c2 = s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s z
d1 = s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s z
d2 = s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s $ s z

Your best bet is to convert the program to use actual integers instead of Peano numbers and run it. First, remove all the type signatures, and then rewrite z, s, a, sb, m, c, and e as the integer equivalents. (The definitions of main, answer, foo, bar, and f don't need to change, as long as you remove the type signature from f.) To help get you started:
z = 0
s x = 1 + x
All the rest should be easy to guess, except that c is a little tricky. Maybe try passing it a few small Peano numbers to figure out what it does:
> zero = z
> one = s z
> two = s (s z)
> c two zero
True
> etc...
Also, e may be confusing, but just use:
e = id

Related

Regex sed issue

My sed expression looks as belos:
sed -i "s/-D CONSOLELOG /-D CONSOLELOG -fPIC /g" makefile.init
makefile.init
CFLAGS = -std=c99 -rdynamic -g -Wall -Wno-write-strings -D CONSOLELOG
Output after 1st Run( As expected)
CFLAGS = -std=c99 -rdynamic -g -Wall -Wno-write-strings -D CONSOLELOG -fPIC
2nd Run (Notice the extra fPIC at the end)
CFLAGS = -std=c99 -rdynamic -g -Wall -Wno-write-strings -D CONSOLELOG -fPIC -fPIC
I need to modify my sed expression to get output as in (1) irrespective of the number of times it is executed
This might work for you (GNU sed):
sed -ri 's/-D CONSOLELOG (-fPIC )?$/&-fPIC /' file
This would insert at most 2 -fPIC options following a -D CONSOLELOG option.
Sample changed for illustration purposes
$ cat ip.txt
42 foo baz
ijk baz xyz
$ sed -i 's/baz $/&123/' ip.txt
$ cat ip.txt
42 foo baz 123
ijk baz xyz
$ # further runs won't change input
$ sed -i 's/baz $/&123/' ip.txt
$ cat ip.txt
42 foo baz 123
ijk baz xyz
$ is a meta character to ensure matching only at end of line
so, matches elsewhere in the line won't be changed and hence applying the command again won't result in duplication
& in replacement section is backreference to entire matched string in search section
since there can only be one match at end of line, g modifier is not needed
To replace anywhere in the line(assuming only single match per line)
$ cat ip.txt
42 foo baz
ijk baz xyz
$ sed -i '/baz 123/! s/baz /&123/' ip.txt
$ cat ip.txt
42 foo baz 123
ijk baz 123xyz
$ # further runs won't change input
$ sed -i '/baz 123/! s/baz /&123/' ip.txt
$ cat ip.txt
42 foo baz 123
ijk baz 123xyz
sed commands can be qualified with addressing
here, /baz 123/! means lines not matching baz 123
Further reading: Difference between single and double quotes in Bash

Indent line ranges with sed?

I'm trying here to convert old fashion phpBB code blocks to MARKDOWN using sed.
Please consider following data sample:
cat sed.txt
[code]xxxx-YYY-xxxx[/code]
Some text
[code]yyyy-ZZZ-yyyy[/code]
More text
Bogus code block[/code]
[code]zzzz-XXX-zzzz[/code]
After long trial and error I've ended up with the following strategy:
sed -ne '
/\[code\].*\[\/code\]/ {
s#\[/*code\]##g
s#^#\n\n #
s#$#\n\n#p
}' sed.txt | cat -Av
$
$
xxxx-YYY-xxxx$
$
$
$
$
yyyy-ZZZ-yyyy$
$
$
$
$
zzzz-XXX-zzzz$
$
$
This works great, however I find it would be easier and seem more natural to do it this way:
sed -ne '
/\[code\].*\[\/code\]/ {
s#\[/*code\]#\n\n#g
s#^# #p
}' sed.txt | cat -Av
$
$
xxxx-YYY-xxxx$
$
$
$
$
yyyy-ZZZ-yyyy$
$
$
$
$
zzzz-XXX-zzzz$
$
$
But that does not work as expected. Any suggestions why, how to get around this?
Thank you
sed '/\[code\].*\[\/code\]/ {
s#\[code]#& #g
s#\[/*code\]#\
\
#g
}' sed.txt
order of substitution is important and changed between your two sample
I also change a bit the behavior, the -n and p are not needed in this text sample (but maybe if coming from a biggest structure)
(test on my aix so posix version)
This might work for you (GNU sed):
sed -nr 's/^\[(code\])(.*)\[\/\1$/\n\n \2\n\n/p' file | sed -n l
N.B. In your script you prepend 2 newlines to the beginning of the pattern space and then prepend 4 spaces again, thus the indentation is added infront of the first of the newlines not infront of the text.

Delete word/digit/symbol - combinations

I'm having trouble to delete a word/digit/symbol combinations.
for example:
-i en -o nl "stackoverflow" -> "-ien-onlstackoverflow" -> "stackoverflow"
-i nl -o nl "stackflow" -> "-inl-onlstackflow" -> "stackflow"
-o dl -v "question" -c1 -> "-odl-v"question-c1 -> "question"
notice that -v is followed by nothing, -i and -o by 2 letters and -c by 1 or more digits
I want to have a command that works on each of this combinations because it is for a script and sed didn't work for some reason.
sed 's#^[-].* \("[[:alnum:]]\{1,\}"\).*#\1#g' 'my_file'
where my file have these data

grep/egrep the star operator not matching all occurrences

Let's take the string AaAa. I want to match the as:
$ echo AaAa | grep -o a
a
a
So it is printing every match and not just the first one. When I add a star after the a I get the following
$ echo AaAa | grep -o 'a*'
$
Why did grep not output every match this time? I know it matched because if we remove the -o option it prints the whole line:
$ echo AaAa | grep 'a*'
AaAa
To see how many matches it should have matched I used sed:
$ echo AaAa | sed 's/a*/x/g'
xAxAx
The strings that were substituted for x should have been what grep -o printed. So the matches are as follows:
The null string in the beginning for matching a zero times
The first a
The second a
Why didn't it print the following?
$ echo AaAa | grep -o 'a*'
a
a
$
EDIT
The above was done with GNU grep 2.5.1
The following was done with GNU grep 2.6.3
$ echo AaAa | grep -o 'a*'
a
a
$
Notice that it still didn't print the first null string on its own line. It seems the bug was partially fixed in this newer release. Shouldn't there be a null string matched as well, like the sed example above?
Let's start with this:
$ echo AaAa | grep -o 'a*'
$
You mentioned this was run on version 2.5.1. This appears to be a bug in grep that seems to have been fixed in 2.5.3.
Here's a quote from GNU grep development:
2.5.3
=====
Fix the combinations:
* -i -o
* --colour -i
* -o -b
* -o and zero-width matches
Go through the bug list im my mailbox and fix fixable.
Fix bugs reported with 2.5.2.
-o and zero-width matches is the bug we seem to be dealing with here. Zero width assertions don't consume characters in the string to the match, but they are still assertions so they do have to match. In this case, our zero width assertion is matching the character a zero times.
On to the next part:
$ echo AaAa | grep -o 'a*'
a
a
$
I think the reason you don't get a blank line here is just that the -o flag just doesn't print anything for zero width assertions.
You can eliminate the duplicates using awk:
$ echo AaAa | grep -o a|awk '!x[$0]++'
a

Regular expression does not match `]` symbol

My goal is to display only the text after last ] symbol.
echo MY_TEXT | grep -o "[^\]]*$"
The output is just the last symbol.
If I change "]" symbol to any letter, it works as expected.
Examples:
$ echo Hello World | grep -o '[^o]*$'
rld # and this is correct!
$ echo He]ll]o Wo]rld | grep -o "[^\]]*$"
d # but expected: rld
Why behavior is different for symbol o and ]?
Thank you in advance.
You do not need to escape the ]:
echo 'He]ll]o Wo]rld' | grep -o "[^]]*$"
Produces: rld
At couple of thing: [ doesn't need escaping inside a character class, you can use --color to see only the letters are match and notice -o splits each match on a new line:
$ echo "He]ll]o Wo]rld" | grep -o '[^]]*$'
rld
$ echo "He]ll]o Wo]rld" | grep --color '[^]]*'
He]ll]o Wo]rld
$ echo "He]ll]o Wo]rld" | grep -o '[^]]*'
He
ll
o Wo
rld
You can strip the ] character using tr among many other ways:
$ echo "He]ll]o Wo]rld" | tr -d ']'
Hello World
Removed the escape character and it worked for me.
$ echo He]ll]o Wo]rld | grep -o "[^]]*$"
> rld