Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
Extracting A String Between Two Characters in Bash

I need help with extracting a string between the "@" symbol and a space " " in Bash.

I'm using Python Twitter Tools, and the output is like this:

430438229200740352 2014-02-03 14:30:45 CST <HorizonAwon> @SawBlastt @WereAutomatic 101 for me to join as well

I need to extract the two strings:

SawBlastt

WereAutomatic

I also need to set them each as a separate variable. I've tried messing around with sed and grep, but no successful results. I'm really stuck on this. Help is very appreciated. Thanks!

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can use:

s='430438229200740352 2014-02-03 14:30:45 CST <HorizonAwon> @SawBlastt @WereAutomatic 101 for me to join as well'
grep -oP '@\K[^ ]*' <<< "$s"
SawBlastt
WereAutomatic
over 4 years ago · Santiago Trujillo Relatório

0

Another gnu grep command, that I used mostly.

grep -Po "(?<=@)[^ ]*" file
over 4 years ago · Santiago Trujillo Relatório

0

BASH has its own regex matching capabilities that will work.

s="430438229200740352 2014-02-03 14:30:45 CST <HorizonAwon> @SawBlastt @WereAutomatic 101 for me to join as well"
if [[ $s =~ @([A-Za-z]+)\ @([A-Za-z]+) ]]; then
    echo ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}
fi

To explain, here's what man bash says:

The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized subexpression.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda