_now="$(date +'%D_%T')"I'd like to replace / and : with _. I'm aware of the following sed command:
echo $_now
Outputs:
01/20/12_16:10:42
sed 's/\//_/gHow do I specify two pattern within the same sed command to replace | and : with _ so that I can get output as 01_20_12_16_10_42?
> s/:/_/g' <<<"$_now"
Outputs:
01_20_12_16_14_09
You can use any one of the following sed substitute find and replace multiple patterns:
OR
sed -e 's/Find/Replace/g' -e 's/Find/Replace/g' <<<"$var"
sed -e 's/Find/Replace/g' -e 's/Find/Replace/g' < inputFile > outputFile
out=$(sed -e 's/Find/Replace/g' -e 's/Find/Replace/g' <<<"$var")
sed 's/Find/Replace/g;s/Find/Replace/g' <<<"$var"
sed -e 's/Find/Replace/g;s/Find/Replace/g' <<<"$var"
sed -e 's/Find/Replace/g;s/Find/Replace/g' < inputFile > outputFile
out=$(sed -e 's/Find/Replace/g;s/Find/Replace/g' <<<"$var")
Examples: Find And Replace Sed Substitute Using a Singe Command Line
Sample outputs:
_now="$(sed -e 's/\//_/g;s/:/_/g' <<<$(date +'%D_%T'))"
echo $_now
01_20_12_16_22_21Here is another version:
Sample outputs:
_now=$(sed 's/[\/:]/_/g' <<<$(date +'%D_%T'))
echo "$_now"
01_20_12_16_24_42
No comments:
Post a Comment