I have a structured text file test.tr
, and I would like to analyze it with an AWK script, but for a special reason I want to get all numbers surrounded with underscores, for example: _0_
should become 0
. This is an example of input text file: s 0.000000000 _0_ RTR
So I'm trying to use the cut
command inside the AWK script as follows:
# AWK script
BEGIN{
# initialization
highest_node_id = 0;
}
{
node_id = $3
node_id = node_id | cut -d "_" -f2 | cut -d "_" -f1 ;# this line causes error
if (node_id > highest_node_id) {
highest_node_id = node_id;
}
}
END{
#print results
}
But I get an error
awk: `analyze.awk: line 37: syntax error at or near cut`
whereas the same command works OK in a bash script.
What should I do?
substr
orgsub
command to remove the surrounding characters instead. See GNU awk: String-Manipulation Functions