In article <me5su4$fd0$
1...@news.albasani.net>,
Hermann Peifer <
pei...@gmx.eu> wrote:
>Hi
>
>I was just wondering if someone had a smart RS value for my gawk script
>at hand: a value that would never occur when reading a binary file (say:
>png image). In the script, I am using FS = "", so that the whole file is
>read into a single record.
>
>In other words, I am looking for the equivalent to using this for text
>files: RS = "\0".
I'm going to assume that the actual problem here (the X in your XY problem)
is "How do I read a whole file in a single go?". Assuming that to be the
case, I will say that:
1) I recently hit this same problem (in the context of parsing
/proc/xxx/status files)
2) I found this (readfile.awk), tucked away in the GAWK distribution,
which seems to fit the bill. I used it in my script like this:
split(readfile("/proc/" pid "/status"),A,"\n")
--- Cut Here ---
# readfile.awk --- read an entire file at once
#
# Original idea by Denis Shirokov,
cosm...@gmail.com, April 2013
#
function readfile(file, tmp, save_rs)
{
save_rs = RS
RS = "^$"
getline tmp < file
close(file)
RS = save_rs
return tmp
}
--- Cut Here ---
>As c.l.a is a give & take, here a 3 short lines for people in desperate
>need of the first million digits of Pi. Expanding the script to getting
>the first 10 million digits isn't too difficult either..
>
>$ gawk -M -vmillion=1 'BEGIN {
> prec = 1e6 * million
> PREC = prec * log(10) / log(2)
> printf "%." prec "f", atan2(0,-1)
>}'
Interesting. I haven't tried it out yet, but note that this depends on
having GMP/MPFR compiled in in your version of GAWK. Correct?
--
There are many self-professed Christians who seem to think that because
they believe in Jesus' sacrifice they can reject Jesus' teachings about
how we should treat others. In this country, they show that they reject
Jesus' teachings by voting for Republicans.