Skip to content

Instantly share code, notes, and snippets.

@laparca
Created April 12, 2019 07:59
Show Gist options
  • Save laparca/db1f78525ee4f6ba60e6d2177e1108d2 to your computer and use it in GitHub Desktop.
Save laparca/db1f78525ee4f6ba60e6d2177e1108d2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Convers a stream of blocks of text into lines. Each line has the whole text of the block.
# For example, for this block
# begin
# some text tha an script put in block
# when we want it in a single line
# because if hard to work with.
# end
# begin
# other interesting text in block
# that should be a line.
# end
# It will be converted into
# begin some text tha an script put in block when we want it in a single line because if hard to work with. end
# begin other interesting text in block that should be a line. end
if [ -z "$1" ] || [ -z "$2" ]; then
echo "It's need a regexp that identifies the first line of the block and the last line of it."
exit 1
fi
BEGIN="$1"
END="$2"
shift 2
sed -n -e "/${BEGIN}/,/${END}/{:x;/${END}/!N;/${END}/b e;b x;:e;s/\n/ /g}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment