rschirin
rschirin

Reputation: 2049

Awk uncorrect tab space

I have some lines like the following saved into a txt file:

 Mike Tyson    1    2    3    4    5
 Alì     1    2   3   4   5

every different fields are separated with a tab, but in the first field I could have 2 words separated only by a space. how can I have a correct interpretation by awk? I want only the values separated by tabs like this:

 $a=mike tyson
 $b=1
 $c=2
 etc etc....

now, i'm using a while cycle to read each line, finished by

 done < <(awk 'NR>0' file.txt)

but this command sees the value "mike tyson" as two different fields.

Upvotes: 1

Views: 239

Answers (2)

janos
janos

Reputation: 124648

The problem is not with awk, as you are interpreting the columns in bash.

Maybe you're looking for something like this:

IFS=$'\t'
while read a b; do
    echo a=$a
    echo b=$b
done < file.txt

In your sample code awk doesn't seem to play any role btw.

Upvotes: 1

Jotne
Jotne

Reputation: 41446

Try to change to:

done < <(awk -F"\t" 'NR>0' file.txt)

awk does see any space (blanks and tabs) as filed separators. Setting it to only tab, prevents it divide files with space.

Upvotes: 3

Related Questions