regex - Grep multiple substrings from a variable without a loop -
regex - Grep multiple substrings from a variable without a loop -
i writing script parse web interface of ups (uninterruptable powerfulness supply) data, given argument provided. have entire script coded correctly accommodate 1 argument.
what accomplish entering 1 string of arguments separated '+' signs, such hostname+model+status+uptime, , grep each one, without using loop. feasible?
the argument assigned $_var utilize of positional parameter $1. said, have set work 1 argument. looking modify script multiple arguments.
#!/bin/bash curl=/usr/bin/curl grep=/bin/grep sed=/bin/sed site=<ommitted> if [ ${#} -lt 1 ] echo "usage: $0 <vars := name|\"name|name\">" exit 1 fi # required parameters _vars=${1} result="$(${curl} -s ${site} | ${sed} -e 's/1,142d//; s/<[^>]*>//g' | ${grep} -w -i -e ${_vars} | ${sed} 's/.*: //; s/^\([0-9.-]\+\) .*/\1/')" echo "${result}"
you can convert + | , utilize grep -e:
vars='hostname+model+status+uptime' ... | grep -e "${vars//+/|}" regex bash sed grep
Comments
Post a Comment