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

302
Visualizações
How to edit a file saved in string using sed?

I need to edit the file saved in a string using sed. As per the below example, I want to change some pattern in the php.ini file. Below example will allow only to change what is saved in the string.

[root@server ~]# PHPINI=/etc/php.ini
[root@server ~]# sed "s/somepattern/changedpattern/" <<< "$PHPINI"

Can somebody help? Thanks in advance.

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

0

You're using the herestring syntax which passes a string on standard input. You should instead pass the name of the file as an argument:

sed 's/somepattern/changedpattern/' /etc/php.ini

To overwrite the existing file, the standard method is to write to a temporary file and then overwrite the original:

sed 's/somepattern/changedpattern/' /etc/php.ini > tmp && mv tmp /etc/php.ini

Some versions of sed support "in-place" editing (which does more or less the same in the background):

sed -i.bak 's/somepattern/changedpattern/' /etc/php.ini

This creates a backup of the original file with a .bak suffix.

If the filename is contained within a variable, then simply use that instead

php_ini=/etc/php.ini
sed -i.bak 's/somepattern/changedpattern/' "$php_ini"

Note my use of lowercase variable names. Uppercase ones should be reserved for use by the shell.

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