-1

例如 cat testing_file.txt 给出

输入:

ABC
ABC                   

预期输出:

ACB
CBA

问题:

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

4

1 回答 1

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。

于 2013-01-21T12:08:54.173 回答