Using read in bash without empty fields collapsing
Posted
by
Charles Duffy
on Stack Overflow
See other posts from Stack Overflow
or by Charles Duffy
Published on 2011-01-07T03:49:55Z
Indexed on
2011/01/07
3:53 UTC
Read the original article
Hit count: 169
bash
I'm trying to read a multi-line tab-separated file in bash. The format is such that empty fields are expected. Unfortunately, the shell is collapsing together field separators which are next to each other, as so:
# IFS=$'\t'
# read one two three <<<$'one\t\tthree'
# printf '<%s> ' "$one" "$two" "$three"; printf '\n'
<one> <three> <>
...as opposed to the desired output of <one> <> <three>
.
Can this be resolved without resorting to a separate language (such as awk)?
© Stack Overflow or respective owner