public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
@ 2016-05-20 18:34 rindeal
  2016-05-20 20:02 ` Amadeusz Żołnowski
  0 siblings, 1 reply; 37+ messages in thread
From: rindeal @ 2016-05-20 18:34 UTC (permalink / raw
  To: gentoo-dev

Have you guys read
https://stackoverflow.com/questions/16529716/awk-save-modifications-inplace
?


^ permalink raw reply	[flat|nested] 37+ messages in thread
* [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
@ 2016-05-18 21:25 aidecoe
  2016-05-18 22:28 ` Göktürk Yüksek
                   ` (4 more replies)
  0 siblings, 5 replies; 37+ messages in thread
From: aidecoe @ 2016-05-18 21:25 UTC (permalink / raw
  To: gentoo-dev; +Cc: Amadeusz Żołnowski

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



^ permalink raw reply related	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2016-05-22  7:45 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-20 18:34 [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place rindeal
2016-05-20 20:02 ` Amadeusz Żołnowski
2016-05-20 20:35   ` rindeal
  -- strict thread matches above, loose matches on Subject: below --
2016-05-18 21:25 aidecoe
2016-05-18 22:28 ` Göktürk Yüksek
2016-05-18 22:53   ` Amadeusz Żołnowski
2016-05-18 23:31     ` Göktürk Yüksek
2016-05-19  0:09       ` Jeroen Roovers
2016-05-19  2:02         ` Göktürk Yüksek
2016-05-19  9:35     ` Ulrich Mueller
2016-05-19 17:51       ` Amadeusz Żołnowski
2016-05-19 18:13         ` Mart Raudsepp
2016-05-19 18:35           ` Ulrich Mueller
2016-05-19 20:04             ` Amadeusz Żołnowski
2016-05-20  9:31               ` Ulrich Mueller
2016-05-18 22:43 ` Robin H. Johnson
2016-05-19 21:50   ` Amadeusz Żołnowski
2016-05-19 22:04     ` Robin H. Johnson
2016-05-20 17:42       ` Amadeusz Żołnowski
2016-05-21 12:20         ` Amadeusz Żołnowski
2016-05-19 23:16 ` Mart Raudsepp
2016-05-19 23:29   ` Göktürk Yüksek
2016-05-20  3:07   ` Mike Frysinger
2016-05-20 16:49   ` Amadeusz Żołnowski
2016-05-20  3:08 ` Mike Frysinger
2016-05-20 19:32   ` Patrice Clement
2016-05-20 19:47     ` rindeal
2016-05-20 20:09   ` Amadeusz Żołnowski
2016-05-21 14:58     ` Mike Frysinger
2016-05-21 16:08       ` Amadeusz Żołnowski
2016-05-21 16:27         ` Kristian Fiskerstrand
2016-05-22  0:45         ` Mike Frysinger
2016-05-22  7:45           ` Michał Górny
2016-05-21 12:45 ` aidecoe
2016-05-21 13:49   ` aidecoe
2016-05-21 20:38     ` Michał Górny
2016-05-21 21:20       ` Amadeusz Żołnowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox