I never cared for SED or AWK because I'm too lazy to learn them.
Python is a very powerful language that's capable of doing almost anything imaginable.
Did you want the hyphens to come in order? e.g. W-ord=-3 would become Word3-=- or would you prefer it to be Word3--= ?
This will spit them out as they come. e.g. Word3-=-
Code: Select all
#!/usr/bin/env python
from sys import stdout, stdin, stderr
data = stdin.read()
numbers = [chr(n) for n in range(48, 58)]
endofline = ["=", "-"]
for line in data.split("\n"):
a = ''
n = ''
eol = ''
for char in line:
if char in numbers:
n += char
elif char in endofline:
eol += char
else:
a += char
stdout.write(a+n+eol+"\n")
This will place them in a specific order. e.g. Word3--=
To change the order all you have to do is change the order of the endofline list. e.g. endofline = ["=", "-"] would result in Word3=--
Code: Select all
#!/usr/bin/env python
from sys import stdout, stdin, stderr
data = stdin.read()
numbers = [chr(n) for n in range(48, 58)]
endofline = ["-", "="]
for line in data.split("\n"):
a = ''
n = ''
eol = ['' for e in endofline]
for char in line:
if char in numbers:
n += char
elif char in endofline:
eol[endofline.index(char)] += char
else:
a += char
e = "".join(eol)
stdout.write(a+n+e+"\n")