If my variable has data as,
test="score=5,grade=d,pass=f,"
Anyway I can extract the data/rewrite the data from/into the variable as,
test="score,grade,pass"
I do not need the data between =, &, and , characters.
If my variable has data as,
test="score=5,grade=d,pass=f,"
Anyway I can extract the data/rewrite the data from/into the variable as,
test="score,grade,pass"
I do not need the data between =, &, and , characters.
In pure bash (no external tools like sed or awk or perl required), you can use "Parameter Expansion" to manipulate strings. You can read about this in Bash's man page.
#!/usr/bin/env bash
test="score=5,grade=d,pass=f,"
# Use the "extglob" shell option for "extended" notation on patterns.
shopt -s extglob
# First, remove the bits from equals to before each comma...
test="${test//=+([^,]),/,}"
# Next, remove the trailing comma.
test="${test%,}"
echo "$test"
And here's a demo.
You may use sed.
echo "score=5,grade=d,pass=f," | sed 's/=[^,]*\(,$\|\)//g'
or
echo "score=5,grade=d,pass=f," | sed 's/=[^,]*\|,$//g'
's/=[^,]*,/,/g;s/,$//' instead. This has pretty much nothing to do with bash.re_format(7) or regex(7) (depending on your OS), the vertical bar is a regular character in BRE. The fact that its ERE functionality can be found in some RE parsers is non-standard and not universal. One option would be to use ERE instead of BRE, i.e. sed -E 's/=[^,]*|,$//g' (or -r for GNU sed and some other implementations). Of course, implementations vary. Use what works. :)