Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove quotes with grep and cut in one command

This is what I do currently:

pass1=$(grep DB_PASSWORD /home/user/public_html/wp-config.php | cut -d ' ' -f3)
# it echoes 'password' with start and end single quotes
pass=${pass1:1:-1}
# it remove single quotes from start and end

But I want to combine these two commands in a single go.

I tried some wrong commands which showed me the help of grep.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use awk:

pass=$(awk -F"'" '/DB_PASSWORD/{print $4}' /home/user/public_html/wp-config.php)

I simply defined ' to be the field separator, which makes the password the 4th field.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading