bash - Ignore empty fields -
given file
$ cat foo.txt ,,,,dog,,,,,111,,,,222,,,333,,,444,,, ,,,,cat,,,,,555,,,,666,,,777,,,888,,, ,,,,mouse,,,,,999,,,,122,,,133,,,144,,,
i can print first field so
$ awk -f, '{print $5}' foo.txt dog cat mouse
however ignore empty fields can call this
$ awk -f, '{print $1}' foo.txt
you can use this:
$ awk -f',+' '{print $2}' file dog cat mouse
similarly, can use $3, $4 , $5 , on.. $1 cannot used in case because records begins delimiter.
Comments
Post a Comment