Read contain files find and print to new file

Hi All,

Sorrry by basic question but I have many files text plane e.g.

$ls  
file1 file2 file3 ..

etc.,

$cat file1

123
244
345
NNN
4234
QQQ
423534

How can read contain each file and find pattern NNN and print in new file output,

$cat newfile
NNN
QQQ

Thanks you,

What is ' file find pattern'?

  1. a pattern in the file name
  2. a pattern in the file's data

What is 'new file output'?

  1. write to a new file
  2. copy the file to a new location

Please give us a sample input and expected output from the sample input.

1 Like

If I'm inferring correctly from that not quite specific request, try grep -o "^[A-Z]{3}$" file*