help-bash
[Top][All Lists]
Advanced

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

Re: A robust but concise way to read TSV header?


From: Alex fxmbsw7 Ratchev
Subject: Re: A robust but concise way to read TSV header?
Date: Thu, 24 Jun 2021 16:23:37 +0200

for data preservation, use mapfile, at least try, ..

On Thu, Jun 24, 2021, 16:17 Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi,
>
> I currently use the following code to get the TSV header into an array.
>
> IFS= read -r line
> readarray -t -d $'\t' array <<< "$line"
> array[-1]=${array[-1]%$'\n'}
>
> The following won't work, as it removes empty fields.
>
> $ IFS=$'\t' read -r -a x <<< $'a\t\tb\t'; declare -p x
> declare -a x=([0]="a" [1]="b")
>
> But the first method is a little long to write. Is there a more
> concise but still robust way to do so in bash?
>
> --
> Regards,
> Peng
>
>


reply via email to

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