I want to remove quotes(double quotes) appearing in the awk output, how it can be achieved
# systool -c fc_host -v | awk '/Class Device =/{host=$4}/port_state/{print host,$3}' (This is my awk output sorted)
"host1" "Online"
"host2" "Online"
Below is the Command & command output..
# systool -c fc_host -v
Class Device = "host1"
Class Device path = "/sys/class/fc_host/host1"
active_fc4s = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 "
fabric_name = "0x100000051ee8aecf"
issue_lip = <store method only>
maxframe_size = "2048 bytes"
node_name = "0x20000000c98f62a7"
port_id = "0x652500"
port_name = "0x10000000c98f62a7"
port_state = "Online"
port_type = "NPort (fabric via point-to-point)"
speed = "8 Gbit"
supported_classes = "Class 3"
supported_fc4s = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 "
supported_speeds = "2 Gbit, 4 Gbit, 8 Gbit"
tgtid_bind_type = "wwpn (World Wide Port Name)"
uevent = <store method only>
Device = "host1"
Device path = "/sys/devices/pci0000:00/0000:00:07.0/0000:0e:00.0/host1"
uevent = <store method only>
Best Answer
Using awk's
substr
functionThis removes the first and last characters from each string:
How it works:
In the code that you started with, there was the line
In the revised code, that is replaced with:
The
substr
function returns a substring of$4
. In this case, it starts from the second character and extends a length oflength($4)-2
. Thus, this includes all characters except the first and last (which are the double quotes).For the same reason, this command:
was replaced with:
Using GNU awk's
gsub
functionAlternatively,
gsub
can be used to remove the double quotes:How it works
This is again just like the code that you started with but with two new commands added:
gsub
does substitutions. In this case, it replaces"
with an empty string, in effect removing the double quotes. On the first line above, it removes them from$4
(which is the host) and on the second line above, it removes them from$3
(which is theport_state
).Using awk's Field Separator