Question

I would like to get the following output and put into an array

grep password /etc/security/user

Output:

password = 123456
password = 412412

I would like to process this and get second portion of the output "123456" & "412412". Preferably place them in an array.

My intent is to check if {sha256} or {sha512} is infront of the password.

Was it helpful?

Solution

With you can use the code to assign passwords into an array:

$ eval $(sed -e 's/.* = //' -e = 1.cat | sed -e 'N;s/\([0-9]\+\)\n\(.*\)/array[\1]="\2"/')
$ echo ${array[1]}, ${array[2]}
123456, 412412

OTHER TIPS

you can do this:

grep password /etc/security/user > input

I know three ways:

1) cut command:

cut -d= -f2 input | cut -c 2-

2) awk command:

awk < input -F= '{ print $2 }' | cut -c 2-

**3) sed command:

cat input | sed "s/.* = //"

Here input is your input file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top