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: Greg Wooledge
Subject: Re: [Help-bash] Is there a way to read the first empty field in a TSV input?
Date: Thu, 28 Sep 2017 13:47:01 -0400
User-agent: NeoMutt/20170113 (1.7.2)

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"



reply via email to

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