Issue
running the following command I get 0271, is there a way to get 0, 27, and 1 separately?
echo '! ibrav = 0, nat = 27, ntyp = 1' | sed -r 's/[^1-9]*//g'
Solution
Use grep
instead of sed
. The -o
option prints just the matching parts, and each match is on a separate line.
echo '! ibrav = 0, nat = 27, ntyp = 1' | grep -E -o '[0-9]+'
Output:
0
27
1
Answered By - Barmar Answer Checked By - Willingham (WPSolving Volunteer)