This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract nth column from file and drop everything after dot

hello, how are you?

I have several table files with the following information, separated by tabs:

GH5_8   Bacteria    Actinoalloteichus fjordicus ADI127-7    APU14662.1
GH5_8   Bacteria    Actinoalloteichus hoggarensis DSM 45943 ASO20105.1
GH5_8   Bacteria    Actinoalloteichus sp. AHMU CJ021    AUS77477.1
GH5_8   Bacteria    Actinoalloteichus sp. GBA129-24 APU20630.1
GH5_8   Bacteria    Actinobacteria bacterium YIM 96077  AYY15149.1
GH5_8   Bacteria    Actinokineospora sp. UTMC 2448  UVS80063.1

and I would like to extract the access codes only (fourth column) and store them in a list XXXX as follows:

APU14662
ASO20105
AUS77477
APU20630
AYY15149
UVS80063

How can I set up the command? Thanks

linux grep

since you tagged this post with several tools "gep cut awk sed" , what have you tried so far ?

What is the separator between the columns, tab?

yes, the separator is tabulation

1 answer

Then

$ cat file | cut -f4 -d$'\t' 
UVS80063.1

should work

cut defaults to tab so you could leave out the delimiter argument. (On the other hand I had no idea bash had this ANSI-C quoting feature so I'm glad you included that!)

thanks, how can I get the ".1" after that?

If you want to remove the stuff including and after the period do:

$ cat file | cut -f4 | cut -f1 -d '.'
UVS80063

Log in to answer this question.