1

I have file named shadow.lab4 which contain below characters and stored in desktop:

$6$bIhKGKp3$LSd47ADZexr.4rBm8y29DLPfd1kxwyuliCea8fExg0ohMT25OAEqUOxKm7t6dj/M50PjACjD.gn.VDD8f4MVy0

Now I am trying to retrieve the encrypted data by using grep command and store it inside variable encr. Then show retrieved data on the screen by using

echo $encr

My expected output should be

LSd47ADZexr.4rBm8y29DLPfd1kxwyuliCea8fExg0ohMT25OAEqUOxKm7t6dj/M50PjACjD.gn.VDD8f4MVy0

Do you know code that I have to use to get my expected output by using 'grep'?

3
  • 3
    The line does not contain sekew; there is no : for the first cut. Your post is very inconsistent. Please update the input data to match the commands in the pipeline. Commented Sep 2, 2012 at 6:29
  • Also in the general case you should usually double-quote your variable interpolations; echo "$encr" Commented Sep 2, 2012 at 6:47
  • I have made changes to the question to make it more clear to be understood. Commented Sep 2, 2012 at 6:55

3 Answers 3

3

I don't know why you use ":" as a separator for cut, but there's no colon at all in your input string. Change the cut part of the script to

cut -d '$' -f 4
Sign up to request clarification or add additional context in comments.

Comments

1

ENCR:

If the encryption is always the 4th field in the string:

encr=$(awk -F "$" '{ print $4 }' shadow.lab4)

If the encryption is always the last field in the string:

encr=$(awk -F "$" '{ print $NF }' shadow.lab4)

Results:

echo "$encr"
LSd47ADZexr.4rBm8y29DLPfd1kxwyuliCea8fExg0ohMT25OAEqUOxKm7t6dj/M50PjACjD.gn.VDD8f4MVy0

SALT:

To access the salt, if it's always the third field:

salt=$(awk -F "$" '{ print $3 }' shadow.lab4)

To access the salt, if it's always the second last field:

salt=$(awk -F "$" '{ print $(NF-1) }' shadow.lab4)

Results:

echo "$salt"
bIhKGKp3

1 Comment

hi, thanks a lot. then how can I take $bIhKGKp3 (which is salt of the encryption) from that file?
0

sed way:

encr = `sed 's/.*\$//' file.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.