[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] feature request: expanding escape sequences
From: |
Ed Morton |
Subject: |
[bug-gawk] feature request: expanding escape sequences |
Date: |
Sat, 05 Jul 2014 09:38:17 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
Guys - I just tried to do something conceptually trivial and discovered there is
literally NO good way to do it in awk so I was wondering if a gawk function
could be provided to do it?
I just want to be able to expand escape sequences in text read
from an input file. For example, let's say I have:
$ cat file
a\tb
c\td
and I want to output:
a<tab>b
c<tab>d
where "<tab>" is a literal control character.
The most concise solution I've come up with is
to invoke the shell to parse the file, e.g.
$ awk '{ system("printf \047" $0 "\n\047") }' file
a b
c d
but that has some caveats, not least of which is that if the input file contains
text like '$(ls)' then that command will be executed!
The alternatives seem to be writing text to manually parse each line to convert
every escape-char to it's literal character, or using a script to read the input
file to generate another script and then execute that.
I'm not looking for an `eval` function, just something that will convert escape
sequences to their equivalent characters so I can do something like this if
`file` contains lines of formatting text:
awk '{ printf expandEscapes($0), "whatever" }' file
and expandEscapes() will just return it's argument as a string with all escape
chars expanded (actual function name up for grabs of course).
What do you think?
Ed.
- [bug-gawk] feature request: expanding escape sequences,
Ed Morton <=