Skip to main content
added 324 characters in body
Source Link
Stéphane Chazelas
  • 584.2k
  • 96
  • 1.1k
  • 1.7k

I'd use perl:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  print $template =~ s/\bvalue1\b/$_/gr' fileA < fileB

If your version of perl is too old to support the r substitute flag, you can use a temporary variable:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  ($out = $template) =~ s/\bvalue1\b/$_/g;
  print $out' fileA < fileB

I'd use perl:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  print $template =~ s/\bvalue1\b/$_/gr' fileA < fileB

I'd use perl:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  print $template =~ s/\bvalue1\b/$_/gr' fileA < fileB

If your version of perl is too old to support the r substitute flag, you can use a temporary variable:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  ($out = $template) =~ s/\bvalue1\b/$_/g;
  print $out' fileA < fileB
Source Link
Stéphane Chazelas
  • 584.2k
  • 96
  • 1.1k
  • 1.7k

I'd use perl:

perl -ne '
  BEGIN{
    local $/ = undef;
    $template = <STDIN>; # slurp file B in
  }
  chomp;
  print $template =~ s/\bvalue1\b/$_/gr' fileA < fileB