bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Inconsistent results between mac and linux when $'\t' is


From: arnold
Subject: Re: [bug-gawk] Inconsistent results between mac and linux when $'\t' is used in a cmmand
Date: Tue, 29 Nov 2016 10:40:59 -0700
User-agent: Heirloom mailx 12.4 7/29/08

Hi.

This isn't really an awk issue.

But to answer your question: $'\t' is a Bash-ism.  On Linux your shell
might be dash and not Bash.  Fortunately, since awk is processing the
string before invoking the shell, you can just use:

        print | "sort -t '\t' -k 1,1n"

and it will work portably.

HTH,

Arnold

Peng Yu <address@hidden> wrote:

> Hi,
>
> I have the following awk code.
>
> ~$ cat main.awk
> {
>   print | "sort -t $'\t' -k 1,1n"
> }
>
> When I run it on Mac, it works just fine.
>
> ~$ uname
> Darwin
> ~$ gawk --version|head -n 1
> GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.1)
> ~$ seq 3| gawk -f ./main.awk
> 1
> 2
> 3
>
> But when I run it on linux. it does not work as expected.
>
> ~$ uname
> Linux
> ~$ gawk --version|head -n 1
> GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.1)
> ~$ seq 3 | gawk -f ./main.awk
> sort: multi-character tab ‘$\t’
>
> Does anybody know why there is a difference between mac and linux? Thanks.
>
> -- 
> Regards,
> Peng
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]