4 ms·
you were close! the following works as well awk -v FS="\t"
by cauthon 7y ago
you were close! the following works as well
awk -v FS="\t"
- 3xblah 7y agoIf I am not mistaken, -v is GAWK only.
- jabl 7y agoSo is -F, IIRC.
- Annatar 7y ago-F has always been supported by real UNIX®️ AWK; that's where -v and -F come from.
- 3xblah 7y agoBUGS The -F option is not necessary given the command line variable assignment feature; it remains only for backwards compatibility. EXAMPLES Print and sort the login names of all users: BEGIN { FS = ":" } { print $1 | "sort" } The above is from the GAWK manpage. FWIW, the first example under EXAMPLES uses FS not -F. There is nothing wrong with using FS instead of -F.
- Annatar 7y agoGAWK is not a real AWK!!! When will you people learn that GNU is not UNIX®️? FS is not used on the command line and doing so is asking for trouble. FS is a built-in variable and as such is treated specially.
- Annatar 7y agoEvery contemporary AWK supports -v. Real AWK from UNIX®️ supported -v since at least the '80's.
- 3xblah 7y agoTrue. But there are differences when -v is used, as opposed to FS. Try this, where "nawk" is Lucent awk used by BSD cat > 1.awk << eof { print $ARGC } eof echo|nawk -f 1.awk FS=":" echo|gawk -f 1.awk FS=":" echo|nawk -f 1.awk -v FS=":" echo|gawk -f 1.awk -v FS=":"
- Annatar 7y agoThat is not how FS is set; It's set with -F. And there is actually no need to use -v, passing variables at the end works consistently across all AWK's and always has: echo "" | awk '{print Bla;}' Bla="Hello."