I have a text file with tabs as separator:
a 1 956 9723
b 2 2 11432
c 3 1307 2964
c 4 2 12586
d 5 1377 11726
e 6 1735 8416
f 7 1320 10443
g 8 1175 9240
h 9 1598 9357
i 10 1405 2066
and I followed the example on nixCraft to extract the first column and last column:
while IFS="\t" read -r f1 f2 f3 f4
do
echo "$f1"
echo "$f4"
done < file.txt
It just returns the whole line. What went wrong?
System: CentOS 7, bash 4.2
IFS=$'\t'or use a literal TAB in IFS.IFS=$"\t"'cause I saw some post on SO using dollar sign before the separator, but it didn't work. However, you suggestion worked! Could you please explain more about the single/doube quote here?$'..'is a carryover fromkshontobash'n some other shells, most notably,zsh. What it does is express escape sequences, e.g.,\n\tetc. With double quotes, it's not special and IFS gets set to two chars backslash n atand since you did not have atin your input you didn't observer it's after effects. Try with IFS=$"\t" and some lines with "t" sprinkled in them....