1 |
From: Amadeusz Żołnowski <aidecoe@g.o> |
2 |
|
3 |
awk doesn't have the -i option like sed and if editing file in place is |
4 |
desired, additional steps are required. eawk uses tmp file to make it |
5 |
look to the caller editing happens in place. |
6 |
--- |
7 |
eclass/eutils.eclass | 13 +++++++++++++ |
8 |
1 file changed, 13 insertions(+) |
9 |
|
10 |
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass |
11 |
index dbedffe..e331f1b 100644 |
12 |
--- a/eclass/eutils.eclass |
13 |
+++ b/eclass/eutils.eclass |
14 |
@@ -20,6 +20,19 @@ _EUTILS_ECLASS=1 |
15 |
|
16 |
inherit multilib toolchain-funcs |
17 |
|
18 |
+# @FUNCTION: eawk |
19 |
+# @USAGE: <file> <args> |
20 |
+# @DESCRIPTION: |
21 |
+# Edit file <file> in place with awk. Pass all arguments following <file> to |
22 |
+# awk. |
23 |
+eawk() { |
24 |
+ local f="$1"; shift |
25 |
+ local tmpf="$(emktemp)" |
26 |
+ |
27 |
+ cat "${f}" >"${tmpf}" || return 1 |
28 |
+ awk "$@" "${tmpf}" >"${f}" |
29 |
+} |
30 |
+ |
31 |
# @FUNCTION: eqawarn |
32 |
# @USAGE: [message] |
33 |
# @DESCRIPTION: |
34 |
-- |
35 |
2.8.2 |