Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a properties file which has a password field (key value pair)


I am trying to get the value in my shell script using the awk command

password=`awk -F "=" '{if($1 == "PASSWORD") print $2}' "$PASSWORD.ini"`

But it retrieves only NDhhHcsOBofXUdUzGw5B0Q.

I need the entire password (including the last two = characters).

share|improve this question
Are you base64 encoding passwords? – Evan Teitelman Jul 29 '13 at 13:37
@Evan, yes, that's base64 and if you look at the unencoded value, it's a 16 byte value, so probably a MD5 hash of the password. – Stéphane Chazelas Jul 29 '13 at 14:27
password=$(sed -n 's/^PASSWORD=//p' < "$PASSWORD.ini")
share|improve this answer

cut would be the appropriate tool here if you already have the line extracted:

$ echo 'PASSWORD=NDhhHcsOBofXUdUzGw5B0Q==' | cut -d= -f2-

Here, you're taking fields from the 2nd to the end.

GNU grep with perl regular expressions would also work:

pw=$(grep -oP '^PASSWORD=\K.*' < filename)
share|improve this answer

Using awk:

password=$(awk 'sub(/^PASSWORD=/,"")' < "$PASSWORD.ini")
share|improve this answer

Using awk you are not limited to splitting on single characters. So you could split on D= for example or even PASSWORD=:

password=$(awk -F "D=" '{print $2}' $PASSWORD.ini)


password=$(awk -F "PASSWORD=" '{print $2}' $PASSWORD.ini)
share|improve this answer

There's several nice ways you can do this within awk depending on the particular approach that suits you:

Change your FS:

$ echo 'PASSWORD=NDhhHcsOBofXUdUzGw5B0Q==' | awk -FPASSWORD= '{print $2;}'

Or change your ORS (this is REALLY hacky):

$ echo 'PASSWORD=NDhhHcsOBofXUdUzGS="="; ORS="=";} {for (i=2;i<NF;i++) print $i}'

The robust and generic way:

$ echo 'PASSWORD=NDhhHcsOBofXUdUzGw5B0Q==' | awk 'BEGIN {FS="^[^=]+=";} {print $2;}'

or (in the case of parsing >1 line and finding the one for which you are searching):

$ echo -e 'foo=bar\nPASSWORD=NDhhHcsOBofXUdUzGw5B0Q==\nbaz=quux\n\n' | \
  awk 'BEGIN {FS="^[^=]+=";} /^PASSWORD=/ {print $2;}'
share|improve this answer
Isn't missing the awk call itself from the second code block? – manatwork Jul 29 '13 at 15:56
… which is handled by the final example. – MikeyB Jul 29 '13 at 16:43
Oops, indeed. Sorry, I missed that. – manatwork Jul 29 '13 at 16:55

Using Bash:

while read line ; do
  case $line in
      echo "${line#PASSWORD=}" ;;
done < "$PASSWORD.ini"

The ${variable#text} part strips the text from the variable.

share|improve this answer

And here's a Perl one:

pw=$(perl -ne 'print $1 if /PASSWORD=(.+)/' "$PASSWORD.ini")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.