1

I am quite new to Linux. I have data like the following, it is in a tbl format

>Feature gnl|XXX|IFEJKLFI_79
            locus_tag   IFEJKLFI_05549
            locus_tag   IFEJKLFI_05549
            protein_id  gnl|XXX|IFEJKLFI_05549

>Feature gnl|XXX|IFEJKLFI_88
            locus_tag   IFEJKLFI_05553
            locus_tag   IFEJKLFI_05553
            protein_id  gnl|XXX|IFEJKLFI_05553

I want to extract locus_tag name and match it with the feature name. To elaborate more, I would like the output to look like that

Feature gnl|XXX|IFEJKLFI_79     IFEJKLFI_05549
Feature gnl|XXX|IFEJKLFI_88     IFEJKLFI_05553

Is that possible to use the awk command directly or should I manipulate the data first? And if yes, how to extract the data?

Thanks!!

8
  • 1
    It's not clear what you mean by it is in a tbl format - the text you show doesn't look like the input to or the output from the Unix command tbl as far as I remember (but I haven't used it in about 15 years so I may be forgetting something), nor (if you're trying to save 2 chars by saying tbl instead of table) does it look like tab-separated data, nor it is a visually aligned in tabular format.
    – Ed Morton
    Sep 5, 2022 at 12:17
  • Are the > part of your file? Is that really the exact format you are dealing with? I ask because this looks like it should be a genbank flat file, which doesn't have > and for which there are dedicated parsers.
    – terdon
    Sep 5, 2022 at 13:18
  • Yes ">" is a part of my file. I added another question but in the answer form, could you please have a look at it? Thanks!!
    – ahmedbar
    Sep 6, 2022 at 10:41
  • Are the "locus-tag-like" patterns (e.g. IFEJKLFI_05549 in your first record) allways the same within the same Feature? That is important because if that is true it doesn't matter if we take it from line 2 or 3 (or 4, for that matter) of the Feature record. If there can be different locus_tags, which one should we take?
    – AdminBee
    Sep 6, 2022 at 10:49
  • Yes, under each Feature there are different "locus-tags", but I am interested in some of them and I need to know to which "Feature" the "locus-tag" of interest belongs.
    – ahmedbar
    Sep 6, 2022 at 12:31

1 Answer 1

0

Using any awk if you really do have blank lines between each block of data as shown in your sample input:

$ awk -v RS= '{print $1, $2, $4}' file
>Feature gnl|XXX|IFEJKLFI_79 IFEJKLFI_05549
>Feature gnl|XXX|IFEJKLFI_88 IFEJKLFI_05553

or this if the locus_tag line is always immediately after the feature line as shown in your sample input:

$ awk '/^>/{feat=$0; n=0} ++n==2{print feat, $2}' file
>Feature gnl|XXX|IFEJKLFI_79 IFEJKLFI_05549
>Feature gnl|XXX|IFEJKLFI_88 IFEJKLFI_05553

or this otherwise:

$ awk '/^>/{feat=$0; f=1} f && $1=="locus_tag"{print feat, $2; f=0}' file
>Feature gnl|XXX|IFEJKLFI_79 IFEJKLFI_05549
>Feature gnl|XXX|IFEJKLFI_88 IFEJKLFI_05553
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .