Artificial intelligent assistant

Filter by column value and write to file I have a table like this: BB1520_v1.0_0103 exon 3329 3601 BB1520_v1.0_0103 exon 3650 4040 BB1520_v1.0_0089 exon 1 862 BB1520_v1.0_0089 exon 1312 1357 BB1520_v1.0_0089 exon 1423 1531 BB1520_v1.0_0084 exon 5196 5283 I want to extract the lines by the values in column 1, and save them to 3 different files. I tried with the following code but didn't work: awk -F, '{print >$1".txt"}' file.txt

You have the right approach, but you need to fieldsplit on whitespace, not commas (`-F,`). I'm interpreting your question as "the lines should be saved to files with names equalling that in column 1".


$ cat file.txt
BB1520_v1.0_0103 exon 3329 3601
BB1520_v1.0_0103 exon 3650 4040
BB1520_v1.0_0089 exon 1 862
BB1520_v1.0_0089 exon 1312 1357
BB1520_v1.0_0089 exon 1423 1531
BB1520_v1.0_0084 exon 5196 5283
$ awk '{ print >$1".txt"}' file.txt
$ cat BB1520_v1.0_0103.txt
BB1520_v1.0_0103 exon 3329 3601
BB1520_v1.0_0103 exon 3650 4040

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e56e89f4901efee136e1612ff81f2cf2