dragonbitestail icon

Parse mixed spacing value from prop file

dragonbitestail | PRO | 04/03/18 12:43:40 PM UTC | 0 ⭐ | 284 👁️ | Never ⏰ | []
Bash |

680 B

|

None

|

0 👍

/

0 👎

# Produce test file containing three lines of the same config name/value pair separated
# by variations in one or more space characters which fall into the :blank: character class.
$ PORT=6379; echo -e "port ${PORT}\nport \t${PORT}\nport  \t ${PORT}" > redis.port.conf
 
# Test parse where a successful parse should extract the port number 3 times without extraneous spacing.
 
# FAIL
$  \grep "^port" /tmp/redis.port.conf  | tr -s "[:blank:]" | cut -d" " -f2
6379
        6379
 
# FAIL
$  \grep "^port" /tmp/redis.port.conf  | tr  "[:blank:]" " " | cut -d" " -f2
6379
 
$  \grep "^port" /tmp/redis.port.conf  | tr  "[:blank:]" " " |  tr -s "[:blank:]" | cut -d" " -f2
6379
6379
6379

Comments