help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Is there a way to read empty string with `read`?


From: Peng Yu
Subject: Re: [Help-bash] Is there a way to read empty string with `read`?
Date: Mon, 23 May 2016 09:19:39 -0500

On Monday, May 23, 2016, Greg Wooledge <address@hidden> wrote:

> On Mon, May 23, 2016 at 07:18:16AM -0500, Peng Yu wrote:
> > Hi, The following code shows that an empty string between two TABs can
> > not be captured. Is there a way to let bash read empty strings between
> > TABs?
>
> Convert the tab characters to some other character that is not treated
> as whitespace by IFS, and which also does not appear in the input data.
>
> echo $'one\ttwo\t\tfour' > testfile
> while IFS=$'\002' read -ra array; do
>     declare -p array
> done < <(tr \\t \\002 < testfile)
>
> Multiple consecutive whitespace characters are treated as a single
> delimiter by IFS.  This is by design, as it's what you want 99% of the


In this case, is it better to add an option to read treat each tab as a
separate dilimiter. This will allow bash to read TSV format.


> time, for input files that have fields padded by whitespace.
>


-- 
Regards,
Peng


reply via email to

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