How can I use search and replace to change the contents of a file.
I need to be able to change the 'all to none' and/or 'none to all' without having to manually do it every time for hundreds of lines.
below is a sample text file with lines numbers on the right. I know how to open and close the file for writing already.
Lines
1 define_filter absolute_minimal_filter ------- all
2 define_filter atma_basic_filter -------- ----- none
3 define_filter atma_communication_filter -- all
4 define_filter atma_health_filter ------------- none
5 define_filter atma_misc_filter --------------- all
6 define_filter atma_performance_filter ---- none
7 define_filter atma_supplemental_filter ---- none
Just out of interest, the Perl solution is pretty similar to the sed one:
EDIT: I missed the "||" first time. As separate statements, the second would undo the first. D'oh!
With a well-chosen string in place of "temp" (in two places):
or without a temp string if "all" and "none" never appear on the same line and always end the line: