help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to split fields like awk with FS="\t"? (read)


From: Geir Hauge
Subject: Re: [Help-bash] How to split fields like awk with FS="\t"? (read)
Date: Fri, 15 May 2015 10:51:17 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, May 14, 2015 at 09:00:37PM -0500, Peng Yu wrote:
> Hi, The following code shows that continuos TAB is treated as single
> field separator as explained in "Word Splitting". But such a
> definition is none intuitive. Sometime people what to treat each TAB
> as a separator. Is there a way to do so in bash? Thanks.

One way could be to swap the TABs with a non-blank character. E.g.

$ IFS=, read -ra array < <(printf '%s\t%s\t%s\t%s\n' a b '' c,d | tr '\t,' 
',\t')
$ array=( "address@hidden//$'\t'/,}" )
$ declare -p array
declare -a array='([0]="a" [1]="b" [2]="" [3]="c,d")'

-- 
Geir Hauge



reply via email to

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