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.
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?
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'
Input : abc|def|"ghi|123|789"|mno|"vdv|456"|ghu
Output : abc|def|"ghi123789" |mno|"vdv456"|ghu
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?
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:
<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);
}
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%\"}"
)
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.
I had only tested the above with single line inputs but it's not correctinput
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
is such that this may be a problem , the script can be modifiedeasily enough
to correct for this.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 376 |
Nodes: | 16 (2 / 14) |
Uptime: | 52:29:07 |
Calls: | 8,041 |
Files: | 13,037 |
Messages: | 5,831,890 |