Linux how to make the space similar with previous

天涯浪子 提交于 2019-12-13 05:25:12

问题


I have an input and which to replace certain (row,column) . I have done to replace the (row,Columnn) that needed but how come the whole line formate was shift? Any code need to add in to prevent the format changes?

Code that i am using to replace the (row,column)

cat abc.txt | awk '$1 ~/^0(1?[0-9])|^00(1?[0-9])$/' | awk '{ if (NR==2) $8="9" ;if ($8 == "9") $66="9";print}'

Input File

024    1   1   1   1   1   1   1   1   1   1 248   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1^M
025    1   1   1   1   1   1       1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1       1   1   1   1   1   1^M
026    1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1^M

Output File

024    1   1   1   1   1   1   1   1   1   1 248   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
025 1 1 1 1 1 1 9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1
026    1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1

回答1:


cat inputfile | awk '$1 ~/^0(1?[0-9])|^00(1?[0-9])$/' | awk '{ if (NR==2) $8="9" ;if ($8 == "9") $66="9";print}'|column -t


来源:https://stackoverflow.com/questions/35644415/linux-how-to-make-the-space-similar-with-previous

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!