[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
From:       aidecoe () gentoo ! org
Date:       2016-05-18 21:25:02
Message-ID: 1463606702-16578-1-git-send-email-aidecoe () gentoo ! org
[Download RAW message or body]

From: Amadeusz Żołnowski <aidecoe@gentoo.org>

awk doesn't have the -i option like sed and if editing file in place is
desired, additional steps are required. eawk uses tmp file to make it
look to the caller editing happens in place.
---
 eclass/eutils.eclass | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index dbedffe..e331f1b 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -20,6 +20,19 @@ _EUTILS_ECLASS=1
 
 inherit multilib toolchain-funcs
 
+# @FUNCTION: eawk
+# @USAGE: <file> <args>
+# @DESCRIPTION:
+# Edit file <file> in place with awk. Pass all arguments following <file> to
+# awk.
+eawk() {
+	local f="$1"; shift
+	local tmpf="$(emktemp)"
+
+	cat "${f}" >"${tmpf}" || return 1
+	awk "$@" "${tmpf}" >"${f}"
+}
+
 # @FUNCTION: eqawarn
 # @USAGE: [message]
 # @DESCRIPTION:
-- 
2.8.2


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic