0
cat /path/to/file  | awk '{if ('/^TCF/' || '/^FSTL/' ) print $0;}' > /path/to/output.txt

Hi! This produces an empty output, however it does work on a "textedit document", but not this "Plain text document". Other than that, its no different, only that it does not work.

cat /path/to/file  | awk '{if ($3=="TCF1" || $3=="FSTL7T2" || $3=="GLI3") print $0;}'

This one works fine, but I want all names starting with TCF, not only TCF1.

Please help!

fedorqui
  • 275,237
  • 103
  • 548
  • 598
user2862862
  • 111
  • 1
  • 1
  • 10
  • When you do a test within an `if` statement you need to tell what to test. Change `/^TCF/` to `$0~/^TCF/` – Jotne Oct 15 '13 at 11:12

3 Answers3

1

Instead of

cat /path/to/file  | awk '{if ('/^TCF/' || '/^FSTL/' ) print $0;}' > /path/to/output.txt

you can use

awk '/^TCF/ || /^FSTL/' /path/to/file > /path/to/output.txt

Note '/^TCF/' is wrong, it should be only /^TCF/. Also, avoid using cat as the file can be given as a parameter to awk. Finally, print $0 is the default action of awk, so you can skip it.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
0

This should work:

awk '/^TCF/||/^FSTL/' /path/to/file  >output.txt

The problem with your statement is:

awk '{if ('/^TCF/' || '/^FSTL/' ) print $0;}'

should be:

awk '{if ($0~/^TCF/ || $0~/^FSTL/ ) print $0;}'
Vijay
  • 65,327
  • 90
  • 227
  • 319
0

Thanks guys! It help me to solve it, but I ended up with the following:

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

But, do you know how to:

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