Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbf39e7
commit d3f77a6
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/env bash | ||
|
||
# if there is only one argument, exit | ||
|
||
case $# in | ||
1);; | ||
*) echo "Usage: $0 pattern";exit;; | ||
esac; | ||
|
||
# again - I hope the argument doesn't contain a / | ||
|
||
sed -n ' | ||
'/$1/' !{ | ||
# put the non-matching line in the hold buffer | ||
h | ||
} | ||
'/$1/' { | ||
# found a line that matches | ||
# add the next line to the pattern space | ||
N | ||
# exchange the previous line with the | ||
# 2 in pattern space | ||
x | ||
# now add the two lines back | ||
G | ||
# and print it. | ||
p | ||
# add the three hyphens as a marker | ||
a\ | ||
--- | ||
# remove first 2 lines | ||
s/.*\n.*\n\(.*\)$/\1/ | ||
# and place in the hold buffer for next time | ||
h | ||
}' |