Replace/Remove not specific text in perl

Hello,

Consider that i have many files that have the below format:

file1

900    7777
1000   5   6   23     nnnnnnnnnnnnnnnnnn
1100 kkkkkkk

file2

900    1989
1000   5   3   10  kkkdfdfdffd
1100 kkkkkkk

What i would like to do is on every file to search the line that starts with '1000' and remove everything that exist after the 3rd token e.g for file1 remove everything that exists after '23', and for file2 remove everything that exist after '10'

I know how to search for the line that starts with '1000' but i do not know how to remove the string that exist after the third token.

Best Regards,
Christos

Try:

perl -pe 's/(^1000(\s+\d+){3}).*/\1/' file
nawk '/^1000 /{NF=4;$1=$1}1' infile
nawk '/^1000 /{sub($4".*",$4,$0)}1' infile

You could use a buffer, chomp until you find the line with the 1000, then delimit by spaces or tabs (whatever the character is):

while($buffer = <MYFILE>)
{
  chomp($buffer);
  if('1000' eq (substr $buffer,0,4))
  {
     my @array = split /\s/,$buffer;
     print($array[0] . " " . $array[1] . " " . $array[2] . "\n";
  }
}
perl -pe 's/^1000(\s+\d+){3}\K.*//' your_file

tyler_durden