Given the following command,
echo "1: " | awk '/1/ -F ":" {print $1}'
why does AWK output:
1:
?
The default value of the field separator FS is a string containing a single space, " " . If awk interpreted this value in the usual way, each space character would separate fields, so two spaces in a row would make an empty field between them.
The -f option only controls where the awk program is read from. If enabled, it means that the first filename is in fact the name of a file that contains the awk program. Otherwise, the first filename is the first file to start looking for patterns.
Shell script to change the delimiter of a file:Using the shell substitution command, all the commas are replaced with the colons. '${line/,/:}' will replace only the 1st match. The extra slash in '${line//,/:}' will replace all the matches. Note: This method will work in bash and ksh93 or higher, not in all flavors.
"-F" is a command line argument, not AWK syntax. Try:
echo "1: " | awk -F ":" '/1/ {print $1}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With