I have a batch file which uses sed to replace multiple strings in each line of a text file (hosts) then, later, prepend ::[space] at the beginning of each line. Well, that's the goal...
sed is used because every line must be kept, not just those with a match
Currently, each search/replace is an individual batch line. The challenge is :: is both a legitimate part of the text file and search terms but ALSO a reserved "word" in batch which indicates everything following is a comment.
These lines will not work properly:
sed -i s/::1//g hosts
sed -i s/:://g hosts
... some other stuff happens here like sort and awk (to dedupe)...
sed -i "s/^/:: /" hosts
The goal was to perfect the sequence of operations then change the structure such that sed is fed a text file with all the terms to be deleted so sed would need only 1 pass through the text file.
I tried to find a way to escape those :: characters but all the references I found (robvanderwoude, etc.) didn't show examples so... I tried to escape the :: by using ^:^: which caused sed to crash (I assume, the batch stops after that call.) I also tried changing those lines to : start "" "sed and arguments" which didn't prevent the parsing as a comment.
How can a batch file be written such that it will use sed with :: as part of sed's calling arguments?