I have a file with this content:
$ cat init
Sample text
PM1:alex:1.2.3.4:22:passwordPM
PM2:alice:5.6.7.8:1212:Password
PM3:bob:9.10.11.12:1313:p@ssword
Some other text
Now I want to grep PM1 to PM3 and I want to set some variables and use them in my script:
user1="alex"
ip1="1.2.3.4"
port1="22"
pass1="password"
...
I need an structure could be used in more than PM1 to PM3. may be I have also PM10.
It's clear that we can grep each field but I don't know how we can use them.
grep PM init | cut -d: -f2
grep PM init | cut -d: -f3
grep PM init | cut -d: -f4
# I need to grep field number 5 in this way:
grep PM init | cut -d: -f5-
Update
I need to grep PM if the third letter is number. because if I don't do it may mixed up with passwords(last field).