in reply to How do I delete lines matching a certain condition and make sure each line has the right prefix and suffix?
For your various requirements, you will find the ^ and $ Metacharacters useful; they let you specify the start and end of a line, respectively. You'll also find Look Around Assertions helpful. So for your 4 requirements, something like:
s/^(?!\|)/|/; # Make sure each line starts w/ | s/(?<!\|)\|?\n/||\n/; # Make sure each line ends w/ || s/\|\|(?!$)/| |/g; # Insert space between || if not at the end of a + line s/^[\s\|]*\n//; # Delete rows w/o meaningful characters
Of course, whoever invented this format has given you a raging case of Leaning_toothpick_syndrome.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|