0

I failed to split after the first space with awk.

$ grep ">" Supplemental_dataset_07_NbE_CDS.fasta | awk 'BEGIN { FS = "\t" } {print $1}' | head
>NbD053290.1 Partial, glutelin type-B 2-like  (XP_016462855.1)
>NbD053289.2 GDSL esterase/lipase At2g38180-like  (XP_016505556.1)
>NbD053288.1 SUMO-conjugating enzyme SCE1  (XP_019223445.1)
>NbD053287.1 bifunctional epoxide hydrolase 2-like  (XP_016470817.1)
>NbD053286.1 uncharacterized protein LOC109221334 isoform X1  (XP_019241352.1)
>NbD053285.2 uncharacterized protein LOC107817905  (XP_016499316.1)
>NbD053284.3 cell division cycle protein 123 homolog  (XP_019248046.1)
>NbD053283.1 Partial, probable rhamnogalacturonate lyase B  (XP_009789094.1)
>NbD053282.1 aluminum-activated malate transporter 2-like  (XP_009760052.1)
>NbD053281.1 Partial, uncharacterized protein LOC107803999  (XP_016483291.1)

Unfortunately, the below command removed part of the description:

grep ">" Supplemental_dataset_07_NbE_CDS.fasta | awk 'BEGIN { FS = " " } {print $1","$2}' | head

>NbD053290.1,Partial,
>NbD053289.1,GDSL
>NbD053288.1,SUMO-conjugating
>NbD053287.1,bifunctional
>NbD053286.1,uncharacterized
>NbD053285.1,uncharacterized
>NbD053284.1,cell
>NbD053283.1,Partial,
>NbD053282.1,aluminum-activated
>NbD053281.1,Partial,

How would it be possible to modify the above command to create this output:

>NbD053290.1,Partial, glutelin type-B 2-like  (XP_016462855.1)
>NbD053289.2,GDSL esterase/lipase At2g38180-like  (XP_016505556.1)

Thank you in advance,

2
  • 3
    Edit your question and provide the contents of the file without the commands. – Nasir Riley Jul 13 '20 at 0:32
  • Is the call to head actually a requirement of your use case, or did you only include it to create a short excerpt of the data as an example of how the input looks like? – AdminBee Jul 13 '20 at 12:45
2

This will replace your whole grep | awk | head pipeline:

awk '/>/{sub(/ /,","); print; if (++c == 10) exit}' Supplemental_dataset_07_NbE_CDS.fasta
1
  • 1
    @AdminBee Right, code-only answers often end up in the "possibly low quality post" review queue and it's then up to people familiar with the domain to decide if it is low quality or not. Yes, the OP might be using head for that purpose but idk so I just gave the OP what they asked for and modify the above command - hopefully it's easy to see what part of my code is implementing head and modify it if not required. – Ed Morton Jul 13 '20 at 13:26
0
$ awk -F" " '{ sub(" ",","); print; }' input
>NbD053290.1,Partial, glutelin type-B 2-like  (XP_016462855.1)
>NbD053289.2,GDSL esterase/lipase At2g38180-like  (XP_016505556.1)
>NbD053288.1,SUMO-conjugating enzyme SCE1  (XP_019223445.1)
>NbD053287.1,bifunctional epoxide hydrolase 2-like  (XP_016470817.1)
>NbD053286.1,uncharacterized protein LOC109221334 isoform X1  (XP_019241352.1)
>NbD053285.2,uncharacterized protein LOC107817905  (XP_016499316.1)
>NbD053284.3,cell division cycle protein 123 homolog  (XP_019248046.1)
>NbD053283.1,Partial, probable rhamnogalacturonate lyase B  (XP_009789094.1)
>NbD053282.1,aluminum-activated malate transporter 2-like  (XP_009760052.1)
>NbD053281.1,Partial, uncharacterized protein LOC107803999  (XP_016483291.1)
0
0

using Raku (formerly known as Perl_6)

$ raku -pe 's/\s/,/;'
>NbD053290.1,Partial, glutelin type-B 2-like  (XP_016462855.1)
>NbD053289.2,GDSL esterase/lipase At2g38180-like  (XP_016505556.1)

OR

$ raku -pe 's:5th/<.ws>/,/;' glutelin.txt
>NbD053290.1,Partial, glutelin type-B 2-like  (XP_016462855.1)
>NbD053289.2,GDSL esterase/lipase At2g38180-like  (XP_016505556.1)

https://raku.org/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.