help-bash
[Top][All Lists]
Advanced

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

A robust but concise way to read TSV header?


From: Peng Yu
Subject: A robust but concise way to read TSV header?
Date: Thu, 24 Jun 2021 09:16:54 -0500

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]