I have a file named
$ cat swap aardvark BILL CLINTON dog eternal CLINTON BILL forever BILL good housekeeping BILL
I want to change all occurrences of
and concurrently change all occurrences of
resulting in output as:
aardvark CLINTON BILL dog eternal BILL CLINTON forever CLINTON good housekeeping CLINTON
I know the classic solution:
sed -e 's/BILL/temp/g' -e 's/CLINTON/BILL/g' -e 's/temp/CLINTON/g'
but somebody challenged me, as an exercise, to do it without using a third word.
I was using following command, but it was working only on the first line:
$ sed 's/\(BILL\) \(CLINTON\)/\2 \1/g' swap aardvark CLINTON BILL dog eternal CLINTON BILL forever BILL good housekeeping BILL
Note: I am using Solaris 10 OS.
How could I get the desired output while observing this artificial constraint?
MORBILLIFORM OVERBILLED TOM, BILL, AND HARRISON