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

183
Visualizações
Replace a string using bash file

I have in my package.json file this line :

"version": "5.0.0",

And I want to replace 5.0.0 with another dynamic value. I tried like this :

sed -i "s%5.0.0%5.1.1%g" "package.json" 

But is not good, because I don't know previous value that is 5.0.0. Should I write a regex here?

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

0

Change 5.6.7 to whatever you want. You can grep or find -exec to change many files at once.

sed -i -E 's/"version": "([0-9]+(\.[0-9]+)+)",/"version": "5.6.7",/' package.json
over 4 years ago · Santiago Trujillo Relatório

0

You could use a backreference:

sed -i -E 's/(^ *?"version". *)[0-9.]+(.*)/\1 5.1.1 \2/g''

The \1 guarantees that the string "version" formatted the same as the input, and you don't have to retype this.

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