简体   繁体   English

如何仅删除文件的所有行中的前两个前导空格

[英]how to remove only the first two leading spaces in all lines of a files

my input file is like 我的输入文件就像

  *CONTROL_ADAPTIVE
  $  adpfreq    adptol    adpopt    maxlvl    tbirth    tdeath     lcadp    ioflag
        0.10     5.000         2         3       0.0       0.0         0         0

I JUST want to remove the leading 2 spaces in all the lines. 我只想删除所有行中的前2个空格。

I used 我用了

sed "s/^[ \t]*//" -i inputfile.txt

but it deletes all the space from all the lines.. I just want to shift the complete text in files to two position to left. 但是它会删除所有行中的所有空格。我只想将文件中的完整文本移到左边的两个位置。

Any solutions to this? 对此有何解决方案?

You can specify that you want to delete two matches of the character set in the brackets: 您可以指定要删除括号中字符集的两个匹配项:

sed -r -i "s/^[ \t]{2}//" inputfile.txt

See the output: 看输出:

$ sed -r "s/^[ \t]{2}//" file
*CONTROL_ADAPTIVE
$  adpfreq    adptol    adpopt    maxlvl    tbirth    tdeath     lcadp    ioflag
      0.10     5.000         2         3       0.0       0.0         0         0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM