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 the first empty field in a TSV in


From: Felipe Salvador
Subject: Re: [Help-bash] Is there a way to read the first empty field in a TSV input?
Date: Thu, 5 Oct 2017 23:37:35 +0200
User-agent: NeoMutt/20170113 (1.7.2)

On Thu, Sep 28, 2017 at 12:05:10PM -0400, Greg Wooledge wrote:
> On Thu, Sep 28, 2017 at 10:56:14AM -0500, Peng Yu wrote:
> > Hi,
> > 
> > The following example shows that the variable "a" gets the value of
> > "x" which is the 2nd field of the input. I'd like "a" to always get
> > the first field even it may be empty. Is possible with bash?
> > 
> > ~$ IFS=$'\t' read -r a b c <<< $'\t'x$'\t'y
> 


> 2) Convert the separators into some other character that bash treats
>    the way you want.
> 
> For example:
> 
> IFS=$'\005' read -r a b c < <(tr $'\t' $'\005' <<< $'\tx\ty')


IFS=$'\005' read -r A B C D < <(tr $'\t' $'\005' <<< $'\t2\t4')

Hi,
I'm a bit confused, is IFS=$'\005' treated as a field?
If so I would expect $A= ,$B=2,$C= ,$D=4 an so on...

But I get $A= ,$B=2,$C=4,$D= , while echoing \"$'\t2\t4'\"
return "       2       4" correctly.

Regards
--
Felipe Salvador



reply via email to

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