I'm looking for some guidance on creating a script to find and replace special characters inside a text file.
I've come up with this piece of pseudo code but filling in the blanks is a bit harder:
CP
& replace by newline.Mr. Mime
(with space) & replace by Mr.Mime
(without space)%
& replace with nothing (aka just leave it out)"Find" stands for "Find All Instances".
I've been looking into sed
, but I can't seem to find how I'd handle these special characters. Any ideas much appreciated.
EDIT: As asked hereby an little snippet of the input:
CP 1593
SSS
Sudowoodo♀
ATK DEF STA IV
15 15 15 100.0%
counter
rock slide
CP 1262
SSS
Tangrowth♀4
ATK DEF STA IV
15 15 15 100.0%
vine whip
grass knot
CP 1077
SSS
Mr. Mime♀
ATK DEF STA IV
15 15 15 100.0%
confusion
psychic
And the expected output:
1593 SSS Sudowoodo♀ 15 15 15 100.0 counter rock slide
1262 SSS Tangrowth♀4 15 15 15 100.0 vine whip grass knot
1077 SSS Mr.Mime♀ 15 15 15 100.0 confusion psychic
sed text process is strictly line oriented, so it's pretty difficult to replace newlines with sed.
Untested:
cat file |
tr '\n\t' ' ' |
sed -e 's/ CP /\n/g' \
-e 's/Mr[.] Mime/Mr.Mime/g' \
-e 's/ */ /g' \
-e 's/%//g'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments