命令行 - 在文本文件中,是否可以从特定的列(最后一列)删除减号?

分享于 

4分钟阅读

ubuntu

 

问题:


2794GRM C311175 17.065 14.579 0.041 0.9776 -0.3700 -0.3156


2794GRM C411176 16.942 14.650 0.044 -0.2129 0.6799 -0.0069


2795GRM C111177 16.942 14.792 0.039 -0.1699 -0.1038 -0.0750


2795GRM C211178 17.065 14.863 0.037 0.4158 -0.0119 -0.4087


2795GRM C311179 17.069 15.003 0.029 -0.1180 -0.0134 -0.3801


2795GRM C411180 16.945 15.073 0.020 -1.1317 0.8381 -0.4420


2796GRM C111181 16.946 15.215 0.009 -0.6160 0.7328 0.3329


2796GRM C211182 17.069 15.286 0.004 0.4990 -0.4661 0.0473


2796GRM C311183 17.068 15.428 13.995 1.1753 0.1069 0.4126


2796GRM C411184 16.942 15.497 13.995 0.1072 -0.1759 1.0031


2797GRM C111185 16.942 15.640 13.989 0.0772 -0.7484 0.6072


2797GRM C211186 17.065 15.709 13.987 0.3197 0.7923 0.7660


2797GRM C311187 17.064 15.851 13.987 0.6508 0.1744 0.8011


2797GRM C411188 16.941 15.922 13.988 -0.0779 -0.5235 0.4419


2798GRM C111189 16.940 16.064 13.993 -0.4092 -0.2008 0.0229


2798GRM C211190 17.064 16.135 13.995 -0.0923 -0.0063 -0.2445


2798GRM C311191 17.060 16.277 13.996 -0.6767 -0.0982 0.1754


2798GRM C411192 16.938 16.350 13.991 -0.3535 0.5098 -0.5576


2799GRM C111193 16.941 16.492 13.990 -1.1218 -0.1434 -0.7878


2799GRM C211194 17.062 16.566 13.986 0.4727 -0.4516 -0.1352


2799GRM C311195 17.066 16.708 13.976 0.2361 0.1619 0.0749


2799GRM C411196 16.944 16.779 13.973 0.0201 -0.3561 -0.0658


2800GRM C111197 16.944 16.922 13.973 -0.6244 -0.2583 1.1019


2800GRM C211198 17.065 16.998 13.977 -0.3723 -0.3714 0.1573


2800GRM C311199 17.063 0.099 13.979 -0.0548 -0.1926 -0.0981


2800GRM C411200 16.942 0.172 13.971 -0.0881 0.1676 -0.0564


2801G8LE C6011201 5.831 0.116 10.796 -0.2284 0.5235 -0.4732


2801G8LE C5711202 5.835 0.256 10.802 0.3394 0.2015 -0.6239


2801G8LE C5011203 5.941 0.316 10.877 0.2831 -0.4177 -0.4594


2801G8LE C4011204 5.987 0.424 10.807 -0.0715 -0.4403 0.0066


2801G8LE C3011205 6.118 0.463 10.803 0.1128 0.6914 0.2241


2801G8LE C2011206 6.182 0.514 10.694 -0.1651 0.0946 -0.2201


2801G8LE C1111207 6.315 0.466 10.687 -0.0770 0.3137 -0.3695


2801G8LE C511208 6.368 0.422 10.571 0.4080 0.4664 0.8689


2801G8LE C211209 6.443 0.305 10.562 0.0527 -0.6675 -0.2050


2801G8LE C111210 6.411 0.245 10.447 0.0286 -0.0604 -0.1501


2801G8LE C311211 6.405 0.108 10.435 -0.4744 -0.0151 -0.6526


2801G8LE C711212 6.303 0.052 10.359 0.0532 0.0121 -0.2123


2801G8LE C1411213 6.207 0.134 10.300 -0.0620 -0.3235 -0.2260


2801G8LE C911214 6.219 0.271 10.295 -0.1192 -0.3422 -0.4145


2801G8LE C411215 6.317 0.322 10.379 0.1036 -0.1823 0.1164




答案1:


awk '{sub(/-/,"",$NF)} 1' file



这将一个正则表达式子stitution只应用于第NF列(其中NF是字段的数量),


mlr --nidx put -S '$[NF] =~"^-(.*)" {$[NF] =" 1"}' file



或者,你可以使用锚定的扩展正则表达式来标识最后一列,例如[^[:blank]]+$


sed -E 's/-([^[:blank:]]+)$/ 1/' file




sed -i -E 's/-([^[:blank:]]+)$/ 1/' file



若要只对以一个或多个十进制数字后跟字符串G8LE的行应用替换,可以按如下方式修改sed表达式:


/^[0-9]+G8LE/s/-([^[:blank:]]+)$/ 1/




答案2:

用sed删除/替换第n个字符:


$ sed -i 's/./ /61' file





COM  文件  COL  COMM  文本  TEX  
相关文章