extract nth number in a string using bash commands
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
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