0

cat /path/to/file1 /path/to/file2 | awk '{if ($3~/^TCF/ || $3~/^GLI/) print $0;}' > /path/to/test1.txt

Do you know how to:

Include the first row in file1 in the test1.txt output? And, is it possible to include if TCF and GLI came from file1 or file2?

Thank you very much!

Jinxed
  • 738
  • 7
  • 27
user2862862
  • 111
  • 1
  • 1
  • 10

3 Answers3

1

Try this command:

 awk '$3~/^TCF/ || $3~/^GLI/ || NR==1 { print FILENAME, $0 }' /path/to/file1 /path/to/file2 > /path/to/test1.txt
  • NR is the current record number in the total input stream.
  • FILENAME is the name of the current input file.
kev
  • 155,172
  • 47
  • 273
  • 272
0
awk '{
      if ($3~/^TCF/ || $3~/^GLI/ || NR==1 ) 
      print $0,FILENAME
     }' /path/to/file1 /path/to/file2 >/path/to/test1.txt
Vijay
  • 65,327
  • 90
  • 227
  • 319
0

Can be shorten some

awk '{if ($3~/^TCF|^GLI/ || NR==1 ) print $0,FILENAME}' /path/to/file1 /path/to/file2 > /path/to/test1.txt
Jotne
  • 40,548
  • 12
  • 51
  • 55