Issue
I have a list like below : release=abc,xyz,pqr,bnm and as output I need
abc
xyz
pqr
bnm
I have tried below using sed , it successfully removes , but not able to insert new line after comma , if can help pls
release=abc,xyz,pqr,bnm
for i in $release;do
b=`echo $i| sed 's/,/\\n/g'`
echo $b
done
output: abc xyz pqr bnm which is not expected here as need new line
Solution
There is no need for a loop, as the i
in the loop is abc,xyz,pqr,bnm
You could also just translate the newlines to commas:
release=abc,xyz,pqr,bnm
tr , '\n' <<< $release
Output
abc
xyz
pqr
bnm
If there should be a non whitespace char other than a comma before actually match the comma, you can use sed
with a capture group:
release=abc,xyz,pqr,bnm
sed 's/\([^[:space:],]\),/\1\n/g' <<< $release
Answered By - The fourth bird Answer Checked By - Candace Johnson (WPSolving Volunteer)