“Bash menggantikan string” Kode Jawaban

bash menggantikan substring

echo [string] | sed "s/[original]/[target]/g"
Curious Cobra

BASH SCRIPT: Ganti. dengan :

#To replace the first occurrence of a pattern with a given string,
#use ${parameter/pattern/string}:

#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"    

# prints 'I love Sara and Marry'

#To replace all occurrences, use ${parameter//pattern/string}:

message='The secret code is 12345'
echo "${message//[0-9]/X}"           
# prints 'The secret code is XXXXX'


#(This is documented in the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion".)
Mckynde

Cara mengganti karakter dari string dalam bash

string="abc"
final=${string//[a]/b}

echo $final
Shy Stoat

Bash menggantikan string

string="stirng" ; echo "${string//ir/ri}"
AttractivePenguin

bash menggantikan substring di string

#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"    
# prints 'I love Sara and Marry'
Different Dugong

Bash menggantikan string

#1) Open the file in vi or vim
#2) Run the replacement command in vi (or vim) as follows

# Replace all matching patterns
:s%/PatternToReplace/Replacement

# Replace one matching pattern at a time
:s/PatternToReplace/Replacement
Jacques_Kirstein

Jawaban yang mirip dengan “Bash menggantikan string”

Pertanyaan yang mirip dengan “Bash menggantikan string”

Lebih banyak jawaban terkait untuk “Bash menggantikan string” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya