It doesn't actively hurt you, but it might confuse you later. You
don't need to set OFS (output field separator) if you aren't going to
use it.

Fwiw, if you want commas, this is what I came up with:

awk -F\| 'BEGIN { OFS = "," } { print $6 ; split($6,a,"/") ; str =
sprintf("%04d-%02d-%02d",a[3],a[1],a[2]) ; $6 = str ; print $0 }'

On Sat, Jan 15, 2022 at 11:17 AM Rich Shepard <[email protected]> wrote:
>
> On Sat, 15 Jan 2022, Rich Shepard wrote:
>
> > I don't know perl and have it almost working in awk.
>
> I don't know why the script worked the last time I used it because it
> certainly didn't work this time. However, this brief script works for the
> current data file:
> ------
> #!/usr/bin/gawk -f
> BEGIN { FS=OFS="|" }
> { split ($6, a, "/"); printf "%s,%s,%s,%s,%s,%s-%s-%s,%s\n", $1, $2, $3, $4, 
> $5, a[3], a[1], a[2], $7; }
> ------
>
> The original script has a second split() which sent me off in the wrong
> direction.
>
> Thanks to all who responded,
>
> Rich

Reply via email to