[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: |
Evan Gates |
Subject: |
Re: [Help-bash] Is there a way to read the first empty field in a TSV input? |
Date: |
Fri, 29 Sep 2017 09:26:03 -0700 |
User-agent: |
s-nail v14.8.6 |
Greg Wooledge <address@hidden> wrote:
> On Thu, Sep 28, 2017 at 09:39:34AM -0700, Evan Gates wrote:
> > A third option, manually loop. I ran into this recently writing a gopher
> > client in bash where the separator is tab and all other characters are
> > allowed IIRC. My solution was:
> >
> >
> > pack() {
> > printf '%s\t' "$ft" "$disp" "$sel" "$host" "$port" "$search"
> > }
> >
> > unpack() {
> > local line
> > IFS= read -r line
> > for k in ft disp sel host port search; do
> > printf -v "$k" %s "${line%%$'\t'*}"
> > line=${line#*$'\t'}
> > done
> > }
>
> OK, yeah. Another unpack implementation would look something like:
>
> for k in ft disp sel host port search; do
> IFS= read -r -d $'\t' "$k"
> done <<< "$line"
Ah, much better. Thanks!