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

208
Vistas
sed search and replace between string and last occurence of character

I currently have a bunch of .md5sum files with a md5sum hash value and it's corresponding file name with full absolute path. I'd like to modify these files from being absolute pathing to relative. I think I have it pretty close.

> cat example.md5sum
197f76c53d2918764cfa6463b7221dec  /example/path/to/file/example.null
> cat example.md5sum | sed 's/(  ).*\//  \.\//'
197f76c53d2918764cfa6463b7221dec  /example/path/to/file/example.null

Throwing the regex ( ).*\/ into notepad++ returns /example/path/to/file/ which is what I want. Moving it over to sed does not produce the same match.

The end goal here as mentioned previously is the following:

197f76c53d2918764cfa6463b7221dec  ./example.null
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Looks like a job for sed.

sed -i.bak 's:/.*/:./:' file ...

The -i option tells sed to modify files "in-place" rather than sending the results to stdout. With the substitute command, you can use alternate delimiters -- in this case, I've used a colon, since the text you're matching and using as replacement includes slashes. Makes things easier to read.

I haven't bothered to match the whitespace before the path, because in an md5sum file has a pretty predictable format.

Back up your input files before experimenting.

Note that this is shell agnostic -- you can run it in tcsh or bash or anything else that is able to launch sed with options.

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