I have a file that looks like this:
serverPass i_am_a_password
I am basically looking for a command so I can set an environment variable to i_am_a_password
.
I've tried using grep with serverPass
but I am not sure how to split the output and somehow pipe it to a environment variable assignment.
Any help is appreciated.
CodePudding user response:
This should do it:
PASSWORD=$(cut -d' ' -f2 password.txt)
Now you will have the password in the environment variable called PASSWORD.
Test it with echo $PASSWORD
-d
is the delimiter and -f2
means the field to output.
CodePudding user response:
If sed
is an option, you can try
$ var=$(sed 's/[^ ]* \(.*\)/\1/' input_file)
$ echo "$var"
i_am_a_password