Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sed交换列_Sed_Swap - Fatal编程技术网

使用sed交换列

使用sed交换列,sed,swap,Sed,Swap,我在文件test中有如下数据: 2233:Jorge Bill :56Blue Pkwy :99999 1111:Mary Smith :33Red Street :123456 我想使用sed和grouping交换姓氏和名字,但我的代码不起作用 sed 's/\([^:]*:\)\([^' ']*' '\)\([^:]*\)/\1\3\2' test 你知道怎么回事吗?你忘了在正则表达式中转义单引号,而且你还需要在替换字符串的末尾多加一个正斜杠。我去掉了单引号,就在这里 sed 's/\

我在文件
test
中有如下数据:

2233:Jorge Bill :56Blue Pkwy  :99999
1111:Mary Smith :33Red Street :123456
我想使用sed和grouping交换姓氏和名字,但我的代码不起作用

sed 's/\([^:]*:\)\([^' ']*' '\)\([^:]*\)/\1\3\2' test

你知道怎么回事吗?

你忘了在正则表达式中转义单引号,而且你还需要在替换字符串的末尾多加一个正斜杠。我去掉了单引号,就在这里

sed 's/\([^:]*:\)\([^ ]* \)\([^:]*\)/\1\3\2/' test