Can be shorten some
awk '{if ($3~/^TCF|^GLI/ || NR==1 ) print $0,FILENAME}' /path/to/file1 /path/to/file2 > /path/to/test1.txt
سؤال
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!
المحلول 2
Can be shorten some
awk '{if ($3~/^TCF|^GLI/ || NR==1 ) print $0,FILENAME}' /path/to/file1 /path/to/file2 > /path/to/test1.txt
نصائح أخرى
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.awk '{
if ($3~/^TCF/ || $3~/^GLI/ || NR==1 )
print $0,FILENAME
}' /path/to/file1 /path/to/file2 >/path/to/test1.txt