Dear All
I filtered a tab file with this command
awk -F'\t' '$15~/NO/' famliy.txt
but I want add header of input file to the out file with filtering command (one line command).
Thanks
Dear All
I filtered a tab file with this command
awk -F'\t' '$15~/NO/' famliy.txt
but I want add header of input file to the out file with filtering command (one line command).
Thanks
Assuming the header is the first line of the file:
cat <(head -n 1 famliy.txt) <(awk -F'\t' '$15~/NO/' famliy.txt) > output
$ cat secret_family.txt
header header1
No NO
No Yes
no no
yes No
yes NO
$ awk -F'\t' 'NR == 1 {print;next} $2 ~/NO/ ' secret_family.txt
header header1
No NO
yes NO
*if header doesn't contain "NO",
$ awk -F'\t' 'NR == 1 {print} $2 ~/NO/ ' secret_family.txt
$ awk -F'\t' 'NR == 1 {print;next} NR>2 && $2 ~/NO/ ' secret_family.txt
header header1
yes NO
$ awk -F'\t' '{IGNORECASE=1};NR == 1 {print;next} NR>2 && $2 ~/NO/ ' secret_family.txt
header header1
no no
yes No
yes NO
Hard-code it in using a conditional on NR
or combine this command with a separate preceding head
command. Also, please explain how this is related to bioinformatics.
EDIT: More information.
awk
has builtin variables, one of which is NR
(the current record-number). This can be used as a proxy for line-number when the record separator is a new line. If your header is of constant length and in the same position at the top of the file, you can effectively use line numbers to write conditions. awk 'NR<3 { print }' in_file
would print the first 2 lines of the file in_file
. This can also be achieved with the command head -n 2 in_file
.
I am not sure about awk, but then you can use below mentioned sed command followed by your command to add header to your new file generated. This consider the fact that your header is the 1st line of your file "family.txt" file.
sed '1q;d' famliy.txt >famliy_R1.txt | awk -F'\t' '$15~/NO/' famliy.txt >>famliy_R1.txt
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
same thing can be done with ebay tsv-utils input:
case sensitive filtering of 2nd column with header:
case insensitive filtering of 2nd column with header: