如何将值插入特定的列和行?

时间:2013-01-21 10:57:28

标签: shell

e.g。 cat testing_file.txt给出

输入

ABC
ABC                   

预期产出:

ACB
CBA

问题:

1)如何将值插入特定的列和行?

1 个答案:

答案 0 :(得分:1)

这是否必须在Shell中完成?它在Perl中很简单:

#! /usr/bin/perl

use warnings;
use strict;

while (<>)
{
  unless (/^<234>/)
  {
    my ($from_pos, $length, $to_pos)
        = /^<!!!>/ ? (21, 4, 6) : (7, 3, 21);
    my $old = substr $_, $from_pos, $length, '0' x $length;
    substr $_, $to_pos, $length, $old;
  }

  print;
}

请注意,substr从零开始,因此$from_pos为21或7,而不是22或8。

相关问题