Answers for "awk delimiter comma"

1

awk delimiter

# by default, awk uses empty space(s) as field seperator
# we can specify field seperator ourselves using -F flag

# SINGLE field seperator
echo 'a+b=c' | awk -F'=' '{print NF, $1, $2}'
# NF in awk stands for number of fields
# Returns
2	a+b 	c

# MULTIPLE field seperators
echo 'a+b=c' | awk -F'[+=]' '{print NF, $1, $2, $3}'
# Returns
3	a	b	c
Posted by: Guest on January-26-2021
0

awk delimiter comma

Just use function split in awk command to split a line into an array 'a'
using a choosen string as delimiter as for example ", " in next use case:
echo "hi, bye, hey" | awk '{split($0,a,", "); print a[3],a[2],a[1]}'
Posted by: Guest on October-27-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language