#!/bin/bash
# sed - sed support

set -e


######
# Library

sys_tool_sed_config_init() {
	lib_setting_arrays sed_delimiters
	sed_delimiters=( '|' ',' ':' '@' )

	lib_setting_vars sed_in_place
	sed_in_place=false
}


######
# Low-level functions

sed_run() {
	local -a opts=( -e "$@" )
	! $sed_in_place || opts+=( -i )
	run sed "${opts[@]}"
}


######
# High-level functions

# sed_replace - use sed to search for a pattern and replace
# $1 - search pattern
# $2 - replacement string
sed_replace() { _sed_replace '' "$@"; }
sed_replace_global() { _sed_replace 'g' "$@"; }

_sed_replace() {
	local g=$1
	shift

	min_args 2 "$@"
	local pat=$1
	local str=$2
	shift 2

	local d=$sed_delimiters
	sed_run "s${d}${pat}${d}${str}${d}${g}" "$@"
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:36:13 PDT 2017 by mcsh d14 v0.23.0.