sed's s command operates on the pattern space. By default sed will load one line at a time into the pattern space. So by specifying a flag "1", you ask sed the change the first occurence on each line. With complex sed scripts you can arrange for several lines to be in the pattern buffer at once. But if you try to load the entire file into the pattern buffer and then execute a single s command, you are limiting yourself to small files only. A general sed solution:
sed '-e/swap/{;s/swap/swap1/;:a' '-en;ba' '-e}' <filename
The /swap/{....} will run the program in the braces when a line with "swap" is encountered. The program replaces swap with swap1. Only the first instance on the line is replaced, no 1 flag is needed since that is the default. Then there is an infinite loop reading lines and printing them out. This uses up the rest of the file and sed will automatically terminate the infinite loop.
I have a list of IPs, and I want to delete just '10.0.0.1'. I would like a sed/awk solution that will only delete '10.0.0.1' and not modify all the IPs
10.0.0.1
10.0.0.2
10.0.0.3
10.0.0.4
10.0.0.5
10.0.0.6
10.0.0.7
10.0.0.8
10.0.0.9
10.0.0.10
10.0.0.11
Tried:
sed -e '/10.0.0.1/d' file
sed '/10.0.0.1/d' file
sed 's/10.0.0.1//1' file
but they all modify the list by removing all the instances of 10.0.0.1 out of the list so I'm only left with
2
3
4
5
6
7
8
9
0
1
Any suggestions?