Skip to content

Instantly share code, notes, and snippets.

@shellscriptx
Last active March 4, 2018 19:45
Show Gist options
  • Save shellscriptx/1da0fb0234c4a019cb95a23b146373b5 to your computer and use it in GitHub Desktop.
Save shellscriptx/1da0fb0234c4a019cb95a23b146373b5 to your computer and use it in GitHub Desktop.
[BASHSRC] Dobrar determinados números contidos na expressão.
#!/bin/bash
source builtin.sh
source regex.sh
dobrar_cond()
{
# Dobra somente os números maiores que '30'
[[ $1 -gt 30 ]] && echo $(($1*2)) || echo $1
}
# Valores
chaves='valor: 10, valor: 15, valor: 20, valor: 25, valor: 30, valor: 35, valor: 40, valor: 45, valor: 50'
# Aplica as substituições.
regex.fnreplace '[0-9]+' "$chaves" -1 $REG_CASE dobrar_cond
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment