1

I have a file with the content shown below:

***************Encrypted String***************
 ezF7LcHO0Zlb+8kkBeIwtA== 
**********************************************

I need to get only encrypted password from above. I used Google to search for an answer, and I got this example (below), but it didn't work:

sed -n '/***************Encrypted String***************/,/************************************‌​**********/p' $file

I tried but it didn't work

  • what have you tried? see stackoverflow.com/questions/38972736/… for an example to solve this kind of problem – Sundeep Sep 12 '16 at 12:47
  • sed -n '/BEGIN/,/END/p' $file but it did not work – Sureshchandra Jarugula Sep 12 '16 at 12:50
  • actually i need to get only encrypted password from below. While i am google it i got above example but it didn't work ***************Encrypted String*************** ezF7LcHO0Zlb+8kkBeIwtA== ********************************************** – Sureshchandra Jarugula Sep 12 '16 at 12:59
  • sed -n '/BEGIN/,/END/{/BEGIN/!{/END/!p}}' file – klerk Sep 12 '16 at 13:03
  • i need to get only encrypted password from below. While i am google it i got above example but it didn't work ***************Encrypted String*************** ezF7LcHO0Zlb+8kkBeIwtA== ********************************************** sed -n '/***************Encrypted String***************/,/**********************************************/p' $file is this works, i tryed but it didn't work – Sureshchandra Jarugula Sep 12 '16 at 13:06
1

The problem here is probably that * is a Regular Expression operator, so you have to escape it \* for it to be treated as a literal. Your examples and suggestions referencing the literals BEGIN and END would all have failed without this adaptation.

***************Encrypted String***************
 ezF7LcHO0Zlb+8kkBeIwtA== 
**********************************************

To extract the second line you could use either of these:

sed -n '0,/\*Encrypted String\*/d;p;q' "$file"
sed -n 2p "$file"

The first matches on *Encrypted String* and then prints the next line. Notice that the * characters are written as \* to ensure they are treated as literal asterisks. The second just prints line two of the file.

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