Issue
I am trying to get strings that are separated by colons from a file with grep. I have managed fine so far but I ran into a problem where grep is just ignoring one of the characters I am trying to include in the search.
The file I am searching contains this line
configname:user:ip:password:macaddr
and the command I am running is grep -o "configname:.*:" sshutil_config
I thought this would find "configname:user:" but all it does is remove "macaddr" from the output. configname:user:ip:password:
The username will change and so I never know what it is so I can't grep specifically for it but I will know the configname and so I am trying to search for the username using it. I need to get the username out of the file as input and save it to a variable using usr=$(grep -o "whatever_this_needs_to_be" sshutil_config)
Thanks in advance, -A\\/
Solution
This is also possible if you don't want to use grep
user="$( cut -d ':' -f 2 <<< "$data" )"
Answered By - omerkarabacak