Last active
October 10, 2019 23:03
-
-
Save rf5860/6085c86cd4a99b032a7e079904de3109 to your computer and use it in GitHub Desktop.
Complex Sed Example.sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* n flag - Turn off printing by default */ | |
1{h; /* On the first line, save the line to temporary storage ('hold' buffer) */ | |
d}; /* Then delete the current line and go to the next */ | |
2{H; /* On the second line, append the current line to the 'hold' buffer */ | |
x; /* Swap the line and the 'hold' buffer */ | |
s:\n::; /* Remove newlines from the line */ | |
x; /* Swap it with the 'hold' buffer */ | |
d}; /* Delete the current line */ | |
3{s:\(.*\): (\1):; /* Add a space to the end of the line */ | |
H}; /* Append this line to the 'hold' buffer */ | |
\%/usr/local% {s:\(.*\): [\1]:; /* On lines matching '\/usr\/local\/, Wrap in square brackets, and prepend a space */ | |
H; /* Append this line to the 'hold' buffer */ | |
x; /* Swap it back into the 'line' buffer */ | |
s:\n::g; /* Remove all new lines */ | |
p}; /* Print it */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment