Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Adding features does not necessarily increase functionality -- it just makes the manuals thicker.


devel / comp.lang.awk / AWK Do not print the whole String

SubjectAuthor
* AWK Do not print the whole StringAbdou B
+- Re: AWK Do not print the whole StringJanis Papanagnou
+- Re: AWK Do not print the whole StringBen Bacarisse
+* Re: AWK Do not print the whole StringManuel Collado
|`* Re: AWK Do not print the whole StringAbdou B
| `- Re: AWK Do not print the whole StringKenny McCormack
`- Re: AWK Do not print the whole StringKpop 2GM

1
AWK Do not print the whole String

<c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1164&group=comp.lang.awk#1164

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:2487:b0:67b:3113:f83f with SMTP id i7-20020a05620a248700b0067b3113f83fmr18361534qkn.604.1648033497194;
Wed, 23 Mar 2022 04:04:57 -0700 (PDT)
X-Received: by 2002:a25:f45:0:b0:628:b4c9:7a9f with SMTP id
66-20020a250f45000000b00628b4c97a9fmr31622602ybp.55.1648033496857; Wed, 23
Mar 2022 04:04:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 23 Mar 2022 04:04:56 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=80.12.102.171; posting-account=-uKF4AoAAAAjpqqQ_4bw-dcNRig3TpmU
NNTP-Posting-Host: 80.12.102.171
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
Subject: AWK Do not print the whole String
From: abdou.bourakba@gmail.com (Abdou B)
Injection-Date: Wed, 23 Mar 2022 11:04:57 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: Abdou B - Wed, 23 Mar 2022 11:04 UTC

Hello Guys,

I would like to concatenate all the line of a file in a String.
So I created this awk command :

gawk 'BEGIN{texte=""}{texte=(texte ", " $0); print length(texte);}END{print " -- "texte "--"; print length(texte)}' listvip.properties

But I have a strange result.
It seems AWK concatenate the strings in one.
But it does not display the correct value, AWK retrun only the last line.
But when I used length on the variable texte, I see the actual lentght is greater that what has been display.

Any Solution ?

Best Regards
Abdou

Re: AWK Do not print the whole String

<t1f17o$sgj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1166&group=comp.lang.awk#1166

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: AWK Do not print the whole String
Date: Wed, 23 Mar 2022 12:44:55 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <t1f17o$sgj$1@dont-email.me>
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Mar 2022 11:44:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08198feb9e6c50a0a9f7bba497bf4b5c";
logging-data="29203"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yAZ4KrHDBbrfB/msZk14u"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:HbUDhgYgZ6hhaOgOUQ8Y+KOQAJE=
In-Reply-To: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
 by: Janis Papanagnou - Wed, 23 Mar 2022 11:44 UTC

On 23.03.2022 12:04, Abdou B wrote:
> Hello Guys,
>
> I would like to concatenate all the line of a file in a String.
> So I created this awk command :
>
> gawk 'BEGIN{texte=""}{texte=(texte ", " $0); print length(texte);}END{print " -- "texte "--"; print length(texte)}' listvip.properties
>
> But I have a strange result.
> It seems AWK concatenate the strings in one.
> But it does not display the correct value, AWK retrun only the last line.
> But when I used length on the variable texte, I see the actual lentght is greater that what has been display.
>
> Any Solution ?

It is not clear what happens in your environment, you didn't tell us
anything about it.

What do you see if you redirect the output into a file and use a text
editor to inspect the contents?

gawk '{ texte = texte ", " $0; print length(texte) }
END { print " -- "texte "--"; print length(texte) }
' listvip.properties >output

Janis

>
> Best Regards
> Abdou
>

Re: AWK Do not print the whole String

<87wngkj3d1.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1167&group=comp.lang.awk#1167

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: AWK Do not print the whole String
Date: Wed, 23 Mar 2022 11:49:14 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <87wngkj3d1.fsf@bsb.me.uk>
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e742c43ca1743bcf3f6ce6190600a15e";
logging-data="31426"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+T7QUp4WvHPtyD4NM0+HTnt7EilwJMqBI="
Cancel-Lock: sha1:3p5OTDLT11usxh/27Zr2eK8khw0=
sha1:r6VqvpYmPc/aj41zbhYcfOB8ge4=
X-BSB-Auth: 1.b8008c67c218db4603d8.20220323114914GMT.87wngkj3d1.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 23 Mar 2022 11:49 UTC

Abdou B <abdou.bourakba@gmail.com> writes:

> I would like to concatenate all the line of a file in a String.
> So I created this awk command :
>
> gawk 'BEGIN{texte=""}{texte=(texte ", " $0); print length(texte);}END{print " -- "texte "--"; print length(texte)}' listvip.properties
>
> But I have a strange result.
> It seems AWK concatenate the strings in one.
> But it does not display the correct value, AWK retrun only the last line.
> But when I used length on the variable texte, I see the actual lentght
> is greater that what has been display.

I suspect the input has \r\n line separators and awk is splitting on \n.
I.e. you are getting the output you want, but the display is overwriting
earlier text with later text.

Try setting RS="\r\n" in the BEGIN block.

But, if all you want is to concatenate the input lines without having to
store them just by printing them without a newline: printf(", %s", $0);
and if you don't want the comma at the start:

gawk 'BEGIN{RS="\r\n"} {printf("%s%s", NR > 1? ", " : "", $0)} END{print ""}'

--
Ben.

Re: AWK Do not print the whole String

<623B1766.7070302@users.sourceforge.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1168&group=comp.lang.awk#1168

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!XskOyfN6KimH/UjGsy9Nsw.user.46.165.242.91.POSTED!not-for-mail
From: m-collado@users.sourceforge.net (Manuel Collado)
Newsgroups: comp.lang.awk
Subject: Re: AWK Do not print the whole String
Date: Wed, 23 Mar 2022 13:49:42 +0100
Organization: Aioe.org NNTP Server
Message-ID: <623B1766.7070302@users.sourceforge.net>
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="21936"; posting-host="XskOyfN6KimH/UjGsy9Nsw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101
Thunderbird/38.5.0
X-Antivirus-Status: Clean
X-Antivirus: AVG (VPS 220322-6, 22/3/2022), Outbound message
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manuel Collado - Wed, 23 Mar 2022 12:49 UTC

El 23/03/2022 a las 12:04, Abdou B escribió:
> Hello Guys,
>
> I would like to concatenate all the line of a file in a String.
> So I created this awk command :
>
> gawk 'BEGIN{texte=""}{texte=(texte ", " $0); print length(texte);}END{print " -- "texte "--"; print length(texte)}' listvip.properties
>
> But I have a strange result.

It works OK in my system. No problem.

> It seems AWK concatenate the strings in one.
> But it does not display the correct value, AWK retrun only the last line.

If lines are terminated by CR+LF and the CR char is kept as the final
char of each line, then what is printed en the screen will have the text
lines overprinted.

> But when I used length on the variable texte, I see the actual lentght is greater that what has been display.

A LOCALE problem? Please test:

LC_ALL=C gawk .....

And see if it makes a difference.

>
> Any Solution ?
>
> Best Regards
> Abdou
>

--
Manuel Collado - http://mcollado.z15.es

Re: AWK Do not print the whole String

<eca857df-59c0-4003-a81c-fcd284bfcb0bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1169&group=comp.lang.awk#1169

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:6214:21a9:b0:440:ff7f:5364 with SMTP id t9-20020a05621421a900b00440ff7f5364mr18080223qvc.61.1648043042163;
Wed, 23 Mar 2022 06:44:02 -0700 (PDT)
X-Received: by 2002:a25:c749:0:b0:633:c6d9:252c with SMTP id
w70-20020a25c749000000b00633c6d9252cmr23403385ybe.593.1648043041884; Wed, 23
Mar 2022 06:44:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 23 Mar 2022 06:44:01 -0700 (PDT)
In-Reply-To: <623B1766.7070302@users.sourceforge.net>
Injection-Info: google-groups.googlegroups.com; posting-host=193.253.78.1; posting-account=-uKF4AoAAAAjpqqQ_4bw-dcNRig3TpmU
NNTP-Posting-Host: 193.253.78.1
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com> <623B1766.7070302@users.sourceforge.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eca857df-59c0-4003-a81c-fcd284bfcb0bn@googlegroups.com>
Subject: Re: AWK Do not print the whole String
From: abdou.bourakba@gmail.com (Abdou B)
Injection-Date: Wed, 23 Mar 2022 13:44:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 37
 by: Abdou B - Wed, 23 Mar 2022 13:44 UTC

The dos2unix on my files made it work
Many Thanks to all !

Le mercredi 23 mars 2022 à 13:49:43 UTC+1, Manuel Collado a écrit :
> El 23/03/2022 a las 12:04, Abdou B escribió:
> > Hello Guys,
> >
> > I would like to concatenate all the line of a file in a String.
> > So I created this awk command :
> >
> > gawk 'BEGIN{texte=""}{texte=(texte ", " $0); print length(texte);}END{print " -- "texte "--"; print length(texte)}' listvip.properties
> >
> > But I have a strange result.
> It works OK in my system. No problem.
> > It seems AWK concatenate the strings in one.
> > But it does not display the correct value, AWK retrun only the last line.
> If lines are terminated by CR+LF and the CR char is kept as the final
> char of each line, then what is printed en the screen will have the text
> lines overprinted.
> > But when I used length on the variable texte, I see the actual lentght is greater that what has been display.
> A LOCALE problem? Please test:
>
> LC_ALL=C gawk .....
>
> And see if it makes a difference.
> >
> > Any Solution ?
> >
> > Best Regards
> > Abdou
> >
> --
> Manuel Collado - http://mcollado.z15.es

Re: AWK Do not print the whole String

<t1f8pl$208ji$2@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1170&group=comp.lang.awk#1170

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: AWK Do not print the whole String
Date: Wed, 23 Mar 2022 13:53:57 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t1f8pl$208ji$2@news.xmission.com>
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com> <623B1766.7070302@users.sourceforge.net> <eca857df-59c0-4003-a81c-fcd284bfcb0bn@googlegroups.com>
Injection-Date: Wed, 23 Mar 2022 13:53:57 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2105970"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 23 Mar 2022 13:53 UTC

In article <eca857df-59c0-4003-a81c-fcd284bfcb0bn@googlegroups.com>,
Abdou B <abdou.bourakba@gmail.com> wrote:
>The dos2unix on my files made it work
>Many Thanks to all !

You might also check out a thread of mine on this newsgroup that addresses
this issue. Look for a thread with Subject something like:

Handling DOS (Windows) text files in Unix (Linux) - a nifty extension lib.

Just read the original post; you can ignore all the bozo commentary from
some of the, er, lesser able, members of this group.

--
I am not a troll.
Rick C. Hodgin
I am not a crook.
Rick M. Nixon

Re: AWK Do not print the whole String

<39b4bfd9-0838-4c4d-9353-a01b4a51bbb6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1175&group=comp.lang.awk#1175

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ac8:7dc8:0:b0:2e1:b3ec:6666 with SMTP id c8-20020ac87dc8000000b002e1b3ec6666mr23791028qte.556.1648493239529;
Mon, 28 Mar 2022 11:47:19 -0700 (PDT)
X-Received: by 2002:a0d:fec7:0:b0:2e5:944f:663a with SMTP id
o190-20020a0dfec7000000b002e5944f663amr26736987ywf.87.1648493239332; Mon, 28
Mar 2022 11:47:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Mon, 28 Mar 2022 11:47:19 -0700 (PDT)
In-Reply-To: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:0:0:0:3c3;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:0:0:0:3c3
References: <c59de8d3-bee7-4377-9b73-3ad42c3227den@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <39b4bfd9-0838-4c4d-9353-a01b4a51bbb6n@googlegroups.com>
Subject: Re: AWK Do not print the whole String
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Mon, 28 Mar 2022 18:47:19 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1975
 by: Kpop 2GM - Mon, 28 Mar 2022 18:47 UTC

if you wanna just chain everything onto one line, you don't even need to use print statements, or any statements for that matter :

version 1 :

[g/m/n]awk 'NF-=!$NF' FS='\n\r?|\r\n?' OFS=',' RS='^$'

(if you're very sure the final row isn't +/- 0, and also no empty lines in between)

version 2 :

[g/m/n]awk 'NF-=$NF!~"."' FS='[\n\r]+' OFS=',' RS='^$'

version 3 :

[ g/m]awk 'NF-=$_~FS"$"' FS='[\n\r]+' OFS=',' RS='^$'
nawk 'NF-=$-_~FS"$"' FS='[\n\r]+' OFS=',' RS='^$'

(more verbose but safer approach. this version also squeezes empty lines)

Tested on gawk, mawk134, mawk1.996, and nawk; i
includes tail-excess-delimiter auto-trim

The 4Chan Teller

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor