Why use different FS, the results is different?

# echo '1 2 3 ' | awk -F' ' '{print NF}'
3
# echo '1:2:3:' | awk -F':' '{print NF}'
4

When FS is set to a space character, leading and trailing spaces and tabs are removed from the input line and then any sequence of one or more space and tab characters act as field separators. When FS is another character (such as the colon in your 2nd example), every occurrence of the character acts as a field separator. And, since you have a trailing colon, there is an empty field after the last colon.

3 Likes