An alternative: cut -d <string>?
awk
does allow a string as delimiter:
$ awk -F"_upstream_" '{print $1}' fileaedes_aegyptianopheles_albimanusanopheles_arabiensisanopheles_stephensiculex_quinquefasciatusdrosophila_melanogaster
Note for the given input you can also use cut
with _
as delimiter and print first two records:
$ cut -d'_' -f-2 fileaedes_aegyptianopheles_albimanusanopheles_arabiensisanopheles_stephensiculex_quinquefasciatusdrosophila_melanogaster
sed
and grep
can also make it. For example, this grep
uses a look-ahead to print everything from the beginning of the line until you find _upstream
:
$ grep -Po '^\w*(?=_upstream)' fileaedes_aegyptianopheles_albimanusanopheles_arabiensisanopheles_stephensiculex_quinquefasciatusdrosophila_melanogaster