这是我的源文件的示例:
USC00020958 -7777S 656S 721S 803S 891S 975S 972S 941S 906S 809S 695S 605S
USC00021001 378S 389R 448R 522R 628R 736S 774S 742S 674S 562S 454R 376R
USC00021026 689R 729R 792R 873R 969R 1060R 1082R 1068R 1015R 903R 775R 682R
USC00021050 663S 713S 796S 885S 984S 1079S 1122S 1103S 1036S 904C 754S 651S
USC00501466 -77R 8R 168R 408R 593R 723R 733R 660R 529R 273R 54R -7R
USW00501492 -43R 18R 132R 308R 510R 666R 687R 605R 466R 239R 45R 12R
USW00501497 3Q -1Q 0P 203Q 388Q 539Q 558Q 493Q 362Q 175Q 51Q 27Q
USW00501684 -118R 0P 211R 413R 573R 700R 710R 644R 520R 294R 35R -67R
USW00501926 184S 223S 303S 418S 544S 651S 661R 617S 519S 353S 227S -7777S
我想从 1-4 位数字的末尾删除 C、S、R、P、Q,同时保留负 (-) 数,并且在此示例中不修改第一列 (USxxxxxxxxx)。我还想将格式更改为在每个值之间有一个空格(或逗号)。这是我尝试过的,但它没有产生我希望的结果:
[user@host1 ~]# cat sample.txt | sed -E 's/(\S+)\s+(.[0-9]{1,4})[C,S,R,P,Q]/\1 \2/g'
USC00020958 -7777 656S 721 803S 891 975S 972 941S 906 809S 695 605S
USC00021001 378 389R 448 522R 628 736S 774 742S 674 562S 454 376R
USC00021026 689 729R 792 873R 969 1060R 1082 1068R 1015 903R 775 682R
USC00021050 663 713S 796 885S 984 1079S 1122 1103S 1036 904C 754 651S
USC00501466 -77 8R 168 408R 593 723R 733 660R 529 273R 54 -7R
USW00501492 -43 18R 132 308R 510 666R 687 605R 466 239R 45 12R
USW00501497 3 -1Q 0 203Q 388 539Q 558 493Q 362 175Q 51 27Q
USW00501684 -118 0P 211 413R 573 700R 710 644R 520 294R 35 -67R
USW00501926 184 223S 303 418S 544 651S 661 617S 519 353S 227 -7777S