Using cut
to get the first column (separated by ,
)
We can use the arr=( $(command) )
syntax to parse the output to a bash array.
How do I assign the output of a command into an array?
Then we can easily loop over each substring:
#!/bin/bash
arr=( $(keytool -list -keystore /etc/pki/java/cacerts -storepass "changeit" | grep _abc_ | cut -d',' -f1) )
for ss in "${arr[@]}"; do
echo "--> $ss"
done
Local example, we're I've placed the 'input' in a text file to mimic the command:
$ cat input
_abc_sec1, Mar 23, 2021, trustedCertEntry,
_abc_sec2, Aug 30, 2021, trustedCertEntry,
something else
$
$
$ cat tst.sh
#!/bin/bash
arr=( $(cat input| grep _abc_ | cut -d',' -f1) )
for ss in "${arr[@]}"; do
echo "--> $ss"
done
$
$
$ ./tst.sh
--> _abc_sec1
--> _abc_sec2
$