Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

343
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Another gnu grep command, that I used mostly.

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda