Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

You are in a maze of little twisting passages, all different.


devel / comp.unix.shell / Re: Removing extra Delimeter in a text file

SubjectAuthor
* Removing extra Delimeter in a text fileSumit Modi
+- Removing extra Delimeter in a text fileJanis Papanagnou
+* Removing extra Delimeter in a text fileSpiros Bousbouras
|`* Removing extra Delimeter in a text fileSumit Modi
| `* Removing extra Delimeter in a text fileSpiros Bousbouras
|  `* Removing extra Delimeter in a text fileSpiros Bousbouras
|   `- Removing extra Delimeter in a text fileEd Morton
+* Removing extra Delimeter in a text fileLew Pitcher
|`- Removing extra Delimeter in a text fileKaz Kylheku
`- Removing extra Delimeter in a text fileEd Morton

1
Removing extra Delimeter in a text file

<ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7527&group=comp.unix.shell#7527

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:4c9a:0:b0:41b:1957:55b with SMTP id j26-20020ac84c9a000000b0041b1957055bmr29400qtv.4.1697536360435; Tue, 17 Oct 2023 02:52:40 -0700 (PDT)
X-Received: by 2002:a54:440a:0:b0:3ab:81e4:4d78 with SMTP id k10-20020a54440a000000b003ab81e44d78mr555786oiw.8.1697536360204; Tue, 17 Oct 2023 02:52:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!69.80.99.14.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 17 Oct 2023 02:52:39 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=195.112.95.126; posting-account=bXXuaAoAAAC4ZOcsUa7zZJfDDi_Rd2fg
NNTP-Posting-Host: 195.112.95.126
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
Subject: Removing extra Delimeter in a text file
From: sumitmodi1988@gmail.com (Sumit Modi)
Injection-Date: Tue, 17 Oct 2023 09:52:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 10
 by: Sumit Modi - Tue, 17 Oct 2023 09:52 UTC

Hi All,

I have a scenario where i need to remove the extra delimiter in a unix file.

Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
Output : abc|def|"ghi123" |mno|"vdv456"|ghu

I tried different Sed and Awk options but could not get to the solution.
Could you please help me to resolve this riddle?

Thanks in Advance.

Re: Removing extra Delimeter in a text file

<uglmjg$2t7rr$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7528&group=comp.unix.shell#7528

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Tue, 17 Oct 2023 12:10:56 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uglmjg$2t7rr$1@dont-email.me>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 17 Oct 2023 10:10:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bcbf1897f30cd196c92dc4fa5980a76a";
logging-data="3055483"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YkJOQslpoaID3qrs4jKxT"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:+ddd7BYJA1EB6dMXRT1aD+ng0GM=
In-Reply-To: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
 by: Janis Papanagnou - Tue, 17 Oct 2023 10:10 UTC

On 17.10.2023 11:52, Sumit Modi wrote:
> Hi All,
>
> I have a scenario where i need to remove the extra delimiter in a unix file.
>
> Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> Output : abc|def|"ghi123" |mno|"vdv456"|ghu

(I suppose that spurious blank is unintentional.)

>
> I tried different Sed and Awk options but could not get to the solution.
> Could you please help me to resolve this riddle?

Assuming there's only one pipe symbol possible within "..." you can use

sed 's/\("[^"]*\)|\([^"]*"\)/\1\2/g'

Janis

>
> Thanks in Advance.
>

Re: Removing extra Delimeter in a text file

<0Q9+yYI9uiMbbyMX2@bongo-ra.co>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7529&group=comp.unix.shell#7529

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Tue, 17 Oct 2023 10:12:20 -0000 (UTC)
Organization: To protect and to server
Message-ID: <0Q9+yYI9uiMbbyMX2@bongo-ra.co>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 17 Oct 2023 10:12:20 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3701149"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:P9MgWGm2f9DqjTZ0POEi6RPGAZnACgpppI+SdZ8eKQU=
X-Server-Commands: nowebcancel
X-Notice: Filtered by postfilter v. 0.9.3
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Tue, 17 Oct 2023 10:12 UTC

On Tue, 17 Oct 2023 02:52:39 -0700 (PDT)
Sumit Modi <sumitmodi1988@gmail.com> wrote:
> Hi All,
>
> I have a scenario where i need to remove the extra delimiter in a unix file.
>
> Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> Output : abc|def|"ghi123" |mno|"vdv456"|ghu
>
> I tried different Sed and Awk options but could not get to the solution.
> Could you please help me to resolve this riddle?

sed 's/\("[^|]*\)|\([^|]*"\)/\1\2 /g'

Re: Removing extra Delimeter in a text file

<2bae2fe2-2cd2-4358-9c52-18f95f6fd17an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7530&group=comp.unix.shell#7530

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:a09:b0:66d:303a:4aa0 with SMTP id dw9-20020a0562140a0900b0066d303a4aa0mr40304qvb.8.1697549217870;
Tue, 17 Oct 2023 06:26:57 -0700 (PDT)
X-Received: by 2002:a4a:2a5b:0:b0:57b:3a08:62b3 with SMTP id
x27-20020a4a2a5b000000b0057b3a0862b3mr674084oox.1.1697549217621; Tue, 17 Oct
2023 06:26:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.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.unix.shell
Date: Tue, 17 Oct 2023 06:26:57 -0700 (PDT)
In-Reply-To: <0Q9+yYI9uiMbbyMX2@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=195.112.95.126; posting-account=bXXuaAoAAAC4ZOcsUa7zZJfDDi_Rd2fg
NNTP-Posting-Host: 195.112.95.126
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com> <0Q9+yYI9uiMbbyMX2@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2bae2fe2-2cd2-4358-9c52-18f95f6fd17an@googlegroups.com>
Subject: Re: Removing extra Delimeter in a text file
From: sumitmodi1988@gmail.com (Sumit Modi)
Injection-Date: Tue, 17 Oct 2023 13:26:57 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2114
 by: Sumit Modi - Tue, 17 Oct 2023 13:26 UTC

On Tuesday, October 17, 2023 at 12:12:29 PM UTC+2, Spiros Bousbouras wrote:
> On Tue, 17 Oct 2023 02:52:39 -0700 (PDT)
> Sumit Modi <sumitm...@gmail.com> wrote:
> > Hi All,
> >
> > I have a scenario where i need to remove the extra delimiter in a unix file.
> >
> > Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> > Output : abc|def|"ghi123" |mno|"vdv456"|ghu
> >
> > I tried different Sed and Awk options but could not get to the solution..
> > Could you please help me to resolve this riddle?
> sed 's/\("[^|]*\)|\([^|]*"\)/\1\2 /g'

Hi Both,

Thanks for your message.
We can have any number of '|' appearance in ".....". So given Sed command wont work in that case.
Any other solution which can be help this scenario?

> > Input : abc|def|"ghi|123|789"|mno|"vdv|456"|ghu
> > Output : abc|def|"ghi123789" |mno|"vdv456"|ghu

thanks a lot in Advance!!

Re: Removing extra Delimeter in a text file

<ugmbn3$325hl$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7531&group=comp.unix.shell#7531

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!news.neodome.net!usenet.network!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Tue, 17 Oct 2023 16:11:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <ugmbn3$325hl$1@dont-email.me>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 17 Oct 2023 16:11:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="418be37ec484bd63abddf3cdf82ba7b9";
logging-data="3216949"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+3kMCg3SwcAwR1IiHoetvtHe5wi497ms="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:P/GEGsiN6X8cO/cHwVfLe9aptyM=
 by: Lew Pitcher - Tue, 17 Oct 2023 16:11 UTC

On Tue, 17 Oct 2023 02:52:39 -0700, Sumit Modi wrote:

> Hi All,
>
> I have a scenario where i need to remove the extra delimiter in a unix
> file.
>
> Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> Output : abc|def|"ghi123"|mno|"vdv456"|ghu
>
> I tried different Sed and Awk options but could not get to the solution.
> Could you please help me to resolve this riddle?

Janis and Spiros have provided great solutions that fit the subject matter
of comp.unix.shell

But, there are times where the standard shell utilities either cannot
perform a given task, or will do so, but with a very complex setup.
For those times, the "programming language" tools can help. I whipped
up a "simple" lex(1) solution that takes care of your requirements:

------ debar.lex ------------

{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
%}
%x QSTRING QEND
%%
\" {
/* a doublequote starts a quoted string.
** output the doublequote, and process
** following characters as contents of
** quoted string.
*/
putchar(*yytext);
BEGIN QSTRING;
}

.. {
/* any other character is output directly */
putchar(*yytext);
}
<QSTRING>\" {
/* a doublequote within a quoted string
** terminates the quoted string. remove the
** doublequote from the string, clean out any
** bars from the quoted string, output the
** cleaned-up string, then let QEND take care
** of the closing doublequote
*/
yyless(yyleng-1); /* requeue doublequote */
BEGIN QEND; /* use QEND to process it */

char *scratch, *dst,
*src = yytext;

dst = scratch = calloc(yyleng+1,1);
for (size_t len = yyleng; len > 0; --len)
{
if (*src != '|') *dst++ = *src;
++src;
}
fputs(scratch,stdout);
free(scratch);
}

<QSTRING>. {
/* any other character in a quoted string just
** extends the quoted string.
*/
yymore();
}

<QEND>\" {
/* terminate the output quoted string with
** it's doublequote */
putchar(*yytext);
BEGIN INITIAL;
}
%%
int main(void) { yylex(); return 0; }
int yywrap() { return 1; }

To build:
lex debar.lex
cc -o debar lex.yy.c

To run:
echo 'abc|def|"ghi|123"|mno|"vdv|456"|ghu' | debar

--
Lew Pitcher
"In Skills We Trust"

Re: Removing extra Delimeter in a text file

<20231017110735.692@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7532&group=comp.unix.shell#7532

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Tue, 17 Oct 2023 19:53:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 151
Message-ID: <20231017110735.692@kylheku.com>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
<ugmbn3$325hl$1@dont-email.me>
Injection-Date: Tue, 17 Oct 2023 19:53:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fc96faa360b08b4b883bddb5cec8312d";
logging-data="3316428"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Hv1knAX/+xDFHLLVAu0zqzZ44406GIig="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:iiLL0vknAfwnF/LBKKOq+0gnj9Q=
 by: Kaz Kylheku - Tue, 17 Oct 2023 19:53 UTC

On 2023-10-17, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
> On Tue, 17 Oct 2023 02:52:39 -0700, Sumit Modi wrote:
>
>> Hi All,
>>
>> I have a scenario where i need to remove the extra delimiter in a unix
>> file.
>>
>> Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
>> Output : abc|def|"ghi123"|mno|"vdv456"|ghu
>>
>> I tried different Sed and Awk options but could not get to the solution.
>> Could you please help me to resolve this riddle?
>
> Janis and Spiros have provided great solutions that fit the subject matter
> of comp.unix.shell
>
> But, there are times where the standard shell utilities either cannot
> perform a given task, or will do so, but with a very complex setup.
> For those times, the "programming language" tools can help. I whipped
> up a "simple" lex(1) solution that takes care of your requirements:

I'm afraid to opine that you've perpetrated a useless use of lex.

- all your token patterns are trivial one-character matches.

- all the work is done by a state machine made up of Lex start conditions.

The whole thing can be a switch statement in a getchar() loop.

><QSTRING>\" {
> /* a doublequote within a quoted string
> ** terminates the quoted string. remove the
> ** doublequote from the string, clean out any
> ** bars from the quoted string, output the
> ** cleaned-up string, then let QEND take care
> ** of the closing doublequote
> */
> yyless(yyleng-1); /* requeue doublequote */
> BEGIN QEND; /* use QEND to process it */

When the string ends, we should just putchar the double
quote and go straight to the INITIAL state; there is
no need fo the QEND to exist.

I've been using lex for 30 years and don't remember ever
using yyless. I forgot about its existence.

>
> char *scratch, *dst,
> *src = yytext;
>
> dst = scratch = calloc(yyleng+1,1);
> for (size_t len = yyleng; len > 0; --len)
> {
> if (*src != '|') *dst++ = *src;
> ++src;
> }
> fputs(scratch,stdout);
> free(scratch);
> }

I don't understand this. The token here is just a single
character: the double quote we matched; yyleng should be 1; yytext[0] is
'"'; and yytext[1] is 0.

We do not have the accumulated string token in any buffer;
we just shipped it to standard output.

I think this would just work:

<QSTRING>| {
/* Pipe within quoted string is deleted.
** Thus empty action (no state change or putchar).
*/
}

How about something like this:

(Tim Rentsch, please ignore and skp to tail recursive version
below.)

void yylex(void)
{ enum { INITIAL, QSTRING } state = INITIAL;
int ch;

while ((ch = getchar()) != EOF) {
switch (state) {
case INITIAL:
if (ch == '"')
state = QSTRING;
puchar(ch);
break;
case QSTRING:
switch (ch) {
case '|':
break;
case '"':
state = INITIAL;
/* fallthrough */
default:
putchar(ch);
break;
}
}
}
}

Tail recursive version:

void yylex(void);

int yylex_string(void)
{ int ch = getchar(ch);
switch (ch) {
case EOF:
return EOF; /* error: unterminated string */
case '"':
putchar(ch);
return yylex();
default:
putchar(ch);
/* fallthrough */
case '|':
return yylex_string();
}
}

void yylex(void)
{ int ch = getchar(ch);
switch (ch) {
case EOF:
return 0:
case '"':
putchar(ch);
return yylex_string();
default:
putchar(ch);
return yylex();
}
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Removing extra Delimeter in a text file

<mG+lSvKVQLZgc4rdj@bongo-ra.co>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7534&group=comp.unix.shell#7534

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Sat, 21 Oct 2023 11:10:06 -0000 (UTC)
Organization: To protect and to server
Message-ID: <mG+lSvKVQLZgc4rdj@bongo-ra.co>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com> <0Q9+yYI9uiMbbyMX2@bongo-ra.co> <2bae2fe2-2cd2-4358-9c52-18f95f6fd17an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 Oct 2023 11:10:06 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="681462"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:/wUOK/SVoozJDZAu/3qD/RwpJLNTC8waBXK67a2NgCo=
X-Server-Commands: nowebcancel
X-Notice: Filtered by postfilter v. 0.9.3
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Sat, 21 Oct 2023 11:10 UTC

On Tue, 17 Oct 2023 06:26:57 -0700 (PDT)
Sumit Modi <sumitmodi1988@gmail.com> wrote:
> On Tuesday, October 17, 2023 at 12:12:29 PM UTC+2, Spiros Bousbouras wrote:
> > On Tue, 17 Oct 2023 02:52:39 -0700 (PDT)
> > Sumit Modi <sumitm...@gmail.com> wrote:
> > > Hi All,
> > >
> > > I have a scenario where i need to remove the extra delimiter in a unix file.
> > >
> > > Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> > > Output : abc|def|"ghi123" |mno|"vdv456"|ghu
> > >
> > > I tried different Sed and Awk options but could not get to the solution.
> > > Could you please help me to resolve this riddle?
> > sed 's/\("[^|]*\)|\([^|]*"\)/\1\2 /g'
>
> Thanks for your message.
> We can have any number of '|' appearance in ".....". So given Sed command
> wont work in that case.
> Any other solution which can be help this scenario?
>
> > > Input : abc|def|"ghi|123|789"|mno|"vdv|456"|ghu
> > > Output : abc|def|"ghi123789" |mno|"vdv456"|ghu

( IFS=\" ; i=1 ; result=
while read a ; do
for b in $a ; do
if (( i & 1 )) ; then
result="$result$b"\"
else
result="$result${b//|}"\"
fi
i=$(( $i + 1 ))
done
done
echo "${result%\"}"
)

--
vlaho.ninja/prog

Re: Removing extra Delimeter in a text file

<45iKKqwfe0NZk6nrj@bongo-ra.co>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7535&group=comp.unix.shell#7535

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Sun, 22 Oct 2023 09:25:26 -0000 (UTC)
Organization: To protect and to server
Message-ID: <45iKKqwfe0NZk6nrj@bongo-ra.co>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com> <0Q9+yYI9uiMbbyMX2@bongo-ra.co> <2bae2fe2-2cd2-4358-9c52-18f95f6fd17an@googlegroups.com>
<mG+lSvKVQLZgc4rdj@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 Oct 2023 09:25:26 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="957854"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:IxP8lR/3QPyZMNuVnO0gz0aaslKjdaIR5482MZLnUiI=
X-Notice: Filtered by postfilter v. 0.9.3
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Sun, 22 Oct 2023 09:25 UTC

On Sat, 21 Oct 2023 11:10:06 -0000 (UTC)
Spiros Bousbouras <spibou@gmail.com> wrote:
> ( IFS=\" ; i=1 ; result=
> while read a ; do
> for b in $a ; do
> if (( i & 1 )) ; then
> result="$result$b"\"
> else
> result="$result${b//|}"\"
> fi
> i=$(( $i + 1 ))
> done
> done
> echo "${result%\"}"
> )

I had only tested the above with single line inputs but it's not correct
for multiline inputs. Here's a correct version :

( IFS=\"
while read a ; do
result=
i=1
for b in $a ; do
if (( i & 1 )) ; then
result="$result$b"\"
else
result="$result${b//|}"\"
fi
i=$(( $i + 1 ))
done
echo "${result%\"}"
done
) < your-file

If an input line ends with a double quote , this gets removed. If the input
is such that this may be a problem , the script can be modified easily enough
to correct for this.

Re: Removing extra Delimeter in a text file

<uhvuk5$253gg$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7542&group=comp.unix.shell#7542

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Thu, 2 Nov 2023 05:45:25 -0500
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uhvuk5$253gg$2@dont-email.me>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Nov 2023 10:45:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ab053d76d31fbcba3b6053086f44188d";
logging-data="2264592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sx9ZjBebd8wcxfWamngXv"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:VJJX0Llrf3fifNCCvy/31CAZCcc=
In-Reply-To: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
Content-Language: en-US
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 231102-0, 11/1/2023), Outbound message
 by: Ed Morton - Thu, 2 Nov 2023 10:45 UTC

On 10/17/2023 4:52 AM, Sumit Modi wrote:
> Hi All,
>
> I have a scenario where i need to remove the extra delimiter in a unix file.
>
> Input : abc|def|"ghi|123"|mno|"vdv|456"|ghu
> Output : abc|def|"ghi123" |mno|"vdv456"|ghu
>
> I tried different Sed and Awk options but could not get to the solution.
> Could you please help me to resolve this riddle?
>
> Thanks in Advance.

Using any awk for any number of `|` inside the quoted fields:

$ awk 'BEGIN{FS=OFS="\""} {for (i=2; i<=NF; i+=2) gsub(/[|]/,"",$i)} 1' file
abc|def|"ghi123"|mno|"vdv456"|ghu

That assumes you don't have newlines inside the quoted fields. If you do
then see https://stackoverflow.com/q/45420535/1745001 for how to handle
that using awk.

Ed.

Re: Removing extra Delimeter in a text file

<uhvvj6$25ef5$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7543&group=comp.unix.shell#7543

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Removing extra Delimeter in a text file
Date: Thu, 2 Nov 2023 06:01:59 -0500
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <uhvvj6$25ef5$1@dont-email.me>
References: <ca1abffd-7dfb-4121-9b3e-cfba48a49a8cn@googlegroups.com>
<0Q9+yYI9uiMbbyMX2@bongo-ra.co>
<2bae2fe2-2cd2-4358-9c52-18f95f6fd17an@googlegroups.com>
<mG+lSvKVQLZgc4rdj@bongo-ra.co> <45iKKqwfe0NZk6nrj@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Nov 2023 11:01:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ab053d76d31fbcba3b6053086f44188d";
logging-data="2275813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AzGt9GT8jC+yHiaXUC3EA"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CQVH/fLgksn7EqRoLc0JSdcMV/Y=
X-Antivirus: Avast (VPS 231102-0, 11/1/2023), Outbound message
X-Antivirus-Status: Clean
Content-Language: en-US
In-Reply-To: <45iKKqwfe0NZk6nrj@bongo-ra.co>
 by: Ed Morton - Thu, 2 Nov 2023 11:01 UTC

On 10/22/2023 4:25 AM, Spiros Bousbouras wrote:
<snip>
> I had only tested the above with single line inputs but it's not correct
> for multiline inputs. Here's a correct version :
>
> ( IFS=\"
> while read a ; do
> result=
> i=1
> for b in $a ; do
> if (( i & 1 )) ; then
> result="$result$b"\"
> else
> result="$result${b//|}"\"
> fi
> i=$(( $i + 1 ))
> done
> echo "${result%\"}"
> done
> ) < your-file
>
> If an input line ends with a double quote , this gets removed. If the
input
> is such that this may be a problem , the script can be modified
easily enough
> to correct for this.

That would be orders of magnitude slower than an awk script, requires
far more and more complicated code than an awk script, is less portable
than an awk script, would strip backslashes so, for example, `\t` would
become `t`, and exposes the input values to the shell for globbing and
filename expansion so, for example, `*` would become the list of all
files in the directory you run it from. Try it with this input to see
what I mean:

"foo\tbar"|"*"

If you were going to do that in shell then you should read the line into
an array rather than a scalar to loop on "${a[@]}" and add "-r" but it'd
still be far slower, lengthier, more complicated and less portable than
an awk script like

awk '
BEGIN { FS=OFS="\"" }
{ for (i=2; i<=NF; i+=2) gsub(/[|]/,"",$i) }
1' your-file

so there's really no point writing a shell loop to do it.

See
https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice,
https://mywiki.wooledge.org/BashFAQ/001, and
https://mywiki.wooledge.org/Quotes for more information.

Ed.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor