SGR29 SGR29 -3 years ago 58
Bash Question

How can i use awk to ignore a comma?

How can I separate a comma using awk for the below

1, servername, url, Properties, hostname, version, os, application server.


I have saved the above line in a file called test.properties and using the following command

awk '{ print $1 }' test.properties


and i just want the server name to be printed in the output, instead, it prints the whole line.

Should i use cut instead for situations like this?

Answer Source

Given:

$ echo "$txt"
1, servername, url, Properties, hostname, version, os, application server

Just set the field separator properly to a comma:

$ echo "$txt" | awk -F, '{print $1}'    
1

Or, as you say, use cut:

$ echo "$txt" | cut -d , -f1    
1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download