我有一个包含以下行的文件:
(+0.010605625808,-0.187753006816)|000000000100> +
(-0.090206444263,+0.071405023336)|000000000101> +
(-0.090206436813,+0.071404993534)|000000000110> +
(+0.069306485355,+0.012268572114)|000000000111> +
(+0.010605554096,-0.187753051519)|000000001000> +
(-0.104045681655,+0.102472946048)|000000001001> +
我需要获取两个编号列的未标记值:
例如0.010605625808
和0.187753006816
。
这是我希望工作的awk系列
awk '$0 ~ /^\((.*),/ {print $1 "and" $2}' examples.txt
但这是输出:
(+0.217999786139,+0.216710388660)|000000000000>and+
(+0.010605582036,-0.187753096223)|000000000001>and+
(+0.010605548508,-0.187753096223)|000000000010>and+
(-0.090206362307,+0.071405015886)|000000000011>and+
(+0.010605625808,-0.187753006816)|000000000100>and+
(-0.090206444263,+0.071405023336)|000000000101>and+
(-0.090206436813,+0.071404993534)|000000000110>and+
(+0.069306485355,+0.012268572114)|000000000111>and+
(+0.010605554096,-0.187753051519)|000000001000>and+
(-0.104045681655,+0.102472946048)|000000001001>and+
我的问题是regexps还是awk? 感谢。
答案 0 :(得分:2)
你可以简化一点
$ awk -F'[(,)]' '{gsub(/[-+]/,""); print $2,$3}' file
0.010605625808 0.187753006816
0.090206444263 0.071405023336
0.090206436813 0.071404993534
0.069306485355 0.012268572114
0.010605554096 0.187753051519
0.104045681655 0.102472946048
答案 1 :(得分:1)
awk -F'[(),+-]' '{print $3,$5}' file